simplify code

This commit is contained in:
mask-pp 2020-12-04 12:43:50 +08:00
parent 392260a20b
commit 75021e2816

10
tree.go
View File

@ -205,10 +205,8 @@ walk:
"'") "'")
} }
c := path[0]
// slash after param // slash after param
if n.nType == param && c == '/' && len(n.children) == 1 { if n.nType == param && path[0] == '/' && len(n.children) == 1 {
parentFullPathIndex += len(n.path) parentFullPathIndex += len(n.path)
n = n.children[0] n = n.children[0]
n.priority++ n.priority++
@ -217,7 +215,7 @@ walk:
// Check if a child with the next path byte exists // Check if a child with the next path byte exists
for i, max := 0, len(n.indices); i < max; i++ { for i, max := 0, len(n.indices); i < max; i++ {
if c == n.indices[i] { if path[0] == n.indices[i] {
parentFullPathIndex += len(n.path) parentFullPathIndex += len(n.path)
i = n.incrementChildPrio(i) i = n.incrementChildPrio(i)
n = n.children[i] n = n.children[i]
@ -226,9 +224,9 @@ walk:
} }
// Otherwise insert it // Otherwise insert it
if c != ':' && c != '*' { if path[0] != ':' && path[0] != '*' {
// []byte for proper unicode char conversion, see #65 // []byte for proper unicode char conversion, see #65
n.indices += bytesconv.BytesToString([]byte{c}) n.indices += path[0:1]
child := &node{ child := &node{
fullPath: fullPath, fullPath: fullPath,
} }