From dc85754c121b98c6bec2a3206691c64611f87056 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 7 May 2020 15:40:25 +0800 Subject: [PATCH] update countParams Signed-off-by: Bo-Yi Wu --- tree.go | 18 ++++++++---------- tree_test.go | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tree.go b/tree.go index e9349ea9..e3180f47 100644 --- a/tree.go +++ b/tree.go @@ -72,17 +72,15 @@ func longestCommonPrefix(a, b string) int { return i } -func countParams(path string) uint8 { +func countParams(path string) uint16 { var n uint - for i := 0; i < len(path); i++ { - if path[i] == ':' || path[i] == '*' { + for i := range []byte(path) { + switch path[i] { + case ':', '*': n++ } } - if n >= 255 { - return 255 - } - return uint8(n) + return uint16(n) } type nodeType uint8 @@ -101,7 +99,7 @@ type node struct { handlers HandlersChain priority uint32 nType nodeType - maxParams uint8 + maxParams uint16 wildChild bool // fullPath string } @@ -266,7 +264,7 @@ walk: } // Search for a wildcard segment and check the name for invalid characters. -// Returns -1 as index, if no wildcard war found. +// Returns -1 as index, if no wildcard was found. func findWildcard(path string) (wildcard string, i int, valid bool) { // Find start for start, c := range []byte(path) { @@ -290,7 +288,7 @@ func findWildcard(path string) (wildcard string, i int, valid bool) { return "", -1, false } -func (n *node) insertChild(numParams uint8, path string, fullPath string, handlers HandlersChain) { +func (n *node) insertChild(numParams uint16, path string, fullPath string, handlers HandlersChain) { for numParams > 0 { // Find prefix until first wildcard wildcard, i, valid := findWildcard(path) diff --git a/tree_test.go b/tree_test.go index 0fe2fe00..993af08e 100644 --- a/tree_test.go +++ b/tree_test.go @@ -76,8 +76,8 @@ func checkPriorities(t *testing.T, n *node) uint32 { return prio } -func checkMaxParams(t *testing.T, n *node) uint8 { - var maxParams uint8 +func checkMaxParams(t *testing.T, n *node) uint16 { + var maxParams uint16 for i := range n.children { params := checkMaxParams(t, n.children[i]) if params > maxParams {