update countParams

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2020-05-07 15:40:25 +08:00
parent ac41b9b486
commit dc85754c12
2 changed files with 10 additions and 12 deletions

18
tree.go
View File

@ -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)

View File

@ -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 {