Skip to content

Commit 5513927

Browse files
authored
chore(route): remove useless code from tree (#793)
1 parent e8af33f commit 5513927

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

pkg/route/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func (engine *Engine) addRoute(method, path string, handlers app.HandlersChain)
707707

708708
methodRouter := engine.trees.get(method)
709709
if methodRouter == nil {
710-
methodRouter = &router{method: method, root: &node{}, hasTsrHandler: make(map[string]bool)}
710+
methodRouter = &router{method: method, root: &node{}}
711711
engine.trees = append(engine.trees, methodRouter)
712712
}
713713
methodRouter.addRoute(path, handlers)

pkg/route/routes_timing_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type Route struct {
5454
}
5555

5656
func BenchmarkTree_FindStatic(b *testing.B) {
57-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
57+
tree := &router{method: "GET", root: &node{}}
5858

5959
static := []*Route{
6060
{"/"},
@@ -230,7 +230,7 @@ func BenchmarkTree_FindStatic(b *testing.B) {
230230
}
231231

232232
func BenchmarkTree_FindGithub(b *testing.B) {
233-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
233+
tree := &router{method: "GET", root: &node{}}
234234

235235
static := []*Route{
236236
// OAuth Authorizations
@@ -508,7 +508,7 @@ func BenchmarkTree_FindGithub(b *testing.B) {
508508
}
509509

510510
func BenchmarkTree_FindStaticTsr(b *testing.B) {
511-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
511+
tree := &router{method: "GET", root: &node{}}
512512

513513
routes := [...]string{
514514
"/doc/foo/go_faq.html/",
@@ -530,7 +530,7 @@ func BenchmarkTree_FindStaticTsr(b *testing.B) {
530530
}
531531

532532
func BenchmarkTree_FindParam(b *testing.B) {
533-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
533+
tree := &router{method: "GET", root: &node{}}
534534

535535
routes := [...]string{
536536
"/hi/:key1/foo/:key2",
@@ -552,7 +552,7 @@ func BenchmarkTree_FindParam(b *testing.B) {
552552
}
553553

554554
func BenchmarkTree_FindParamTsr(b *testing.B) {
555-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
555+
tree := &router{method: "GET", root: &node{}}
556556

557557
routes := [...]string{
558558
"/hi/:key1/foo/:key2/",
@@ -574,7 +574,7 @@ func BenchmarkTree_FindParamTsr(b *testing.B) {
574574
}
575575

576576
func BenchmarkTree_FindAny(b *testing.B) {
577-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
577+
tree := &router{method: "GET", root: &node{}}
578578

579579
routes := [...]string{
580580
"/hi/*key1",
@@ -596,7 +596,7 @@ func BenchmarkTree_FindAny(b *testing.B) {
596596
}
597597

598598
func BenchmarkTree_FindAnyFallback(b *testing.B) {
599-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
599+
tree := &router{method: "GET", root: &node{}}
600600

601601
routes := [...]string{
602602
"/hi/a/b/c/d/e/*key1",

pkg/route/tree.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ import (
5555
)
5656

5757
type router struct {
58-
method string
59-
root *node
60-
hasTsrHandler map[string]bool
58+
method string
59+
root *node
6160
}
6261

6362
type MethodTrees []*router

pkg/route/tree_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestCountParams(t *testing.T) {
9494
}
9595

9696
func TestEmptyPath(t *testing.T) {
97-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
97+
tree := &router{method: "GET", root: &node{}}
9898

9999
routes := [...]string{
100100
"",
@@ -113,7 +113,7 @@ func TestEmptyPath(t *testing.T) {
113113
}
114114

115115
func TestTreeAddAndGet(t *testing.T) {
116-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
116+
tree := &router{method: "GET", root: &node{}}
117117

118118
routes := [...]string{
119119
"/hi",
@@ -150,7 +150,7 @@ func TestTreeAddAndGet(t *testing.T) {
150150
}
151151

152152
func TestTreeWildcard(t *testing.T) {
153-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
153+
tree := &router{method: "GET", root: &node{}}
154154

155155
routes := [...]string{
156156
"/",
@@ -198,7 +198,7 @@ func TestTreeWildcard(t *testing.T) {
198198
}
199199

200200
func TestUnescapeParameters(t *testing.T) {
201-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
201+
tree := &router{method: "GET", root: &node{}}
202202

203203
routes := [...]string{
204204
"/",
@@ -247,7 +247,7 @@ type testRoute struct {
247247
}
248248

249249
func testRoutes(t *testing.T, routes []testRoute) {
250-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
250+
tree := &router{method: "GET", root: &node{}}
251251

252252
for _, route := range routes {
253253
recv := catchPanic(func() {
@@ -306,7 +306,7 @@ func TestTreeChildConflict(t *testing.T) {
306306
}
307307

308308
func TestTreeDuplicatePath(t *testing.T) {
309-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
309+
tree := &router{method: "GET", root: &node{}}
310310

311311
routes := [...]string{
312312
"/",
@@ -342,7 +342,7 @@ func TestTreeDuplicatePath(t *testing.T) {
342342
}
343343

344344
func TestEmptyWildcardName(t *testing.T) {
345-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
345+
tree := &router{method: "GET", root: &node{}}
346346

347347
routes := [...]string{
348348
"/user:",
@@ -372,7 +372,7 @@ func TestTreeCatchAllConflict(t *testing.T) {
372372
}
373373

374374
func TestTreeCatchMaxParams(t *testing.T) {
375-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
375+
tree := &router{method: "GET", root: &node{}}
376376
route := "/cmd/*filepath"
377377
tree.addRoute(route, fakeHandler(route))
378378
}
@@ -387,7 +387,7 @@ func TestTreeDoubleWildcard(t *testing.T) {
387387
}
388388

389389
for _, route := range routes {
390-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
390+
tree := &router{method: "GET", root: &node{}}
391391
recv := catchPanic(func() {
392392
tree.addRoute(route, nil)
393393
})
@@ -399,7 +399,7 @@ func TestTreeDoubleWildcard(t *testing.T) {
399399
}
400400

401401
func TestTreeTrailingSlashRedirect2(t *testing.T) {
402-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
402+
tree := &router{method: "GET", root: &node{}}
403403

404404
routes := [...]string{
405405
"/api/:version/seller/locales/get",
@@ -444,7 +444,7 @@ func TestTreeTrailingSlashRedirect2(t *testing.T) {
444444
}
445445

446446
func TestTreeTrailingSlashRedirect(t *testing.T) {
447-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
447+
tree := &router{method: "GET", root: &node{}}
448448

449449
routes := [...]string{
450450
"/hi",
@@ -543,7 +543,7 @@ func TestTreeTrailingSlashRedirect(t *testing.T) {
543543
}
544544

545545
func TestTreeRootTrailingSlashRedirect(t *testing.T) {
546-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
546+
tree := &router{method: "GET", root: &node{}}
547547

548548
recv := catchPanic(func() {
549549
tree.addRoute("/:test", fakeHandler("/:test"))
@@ -561,7 +561,7 @@ func TestTreeRootTrailingSlashRedirect(t *testing.T) {
561561
}
562562

563563
func TestTreeFindCaseInsensitivePath(t *testing.T) {
564-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
564+
tree := &router{method: "GET", root: &node{}}
565565

566566
longPath := "/l" + strings.Repeat("o", 128) + "ng"
567567
lOngPath := "/l" + strings.Repeat("O", 128) + "ng/"
@@ -708,7 +708,7 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
708708
}
709709

710710
func TestTreeParamNotOptimize(t *testing.T) {
711-
tree := &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
711+
tree := &router{method: "GET", root: &node{}}
712712
routes := [...]string{
713713
"/:parama/start",
714714
"/:paramb",
@@ -722,7 +722,7 @@ func TestTreeParamNotOptimize(t *testing.T) {
722722
})
723723

724724
// other sequence
725-
tree = &router{method: "GET", root: &node{}, hasTsrHandler: make(map[string]bool)}
725+
tree = &router{method: "GET", root: &node{}}
726726
routes = [...]string{
727727
"/:paramb",
728728
"/:parama/start",

0 commit comments

Comments
 (0)