mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 23:12:17 +08:00
update countParams
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
ac41b9b486
commit
dc85754c12
18
tree.go
18
tree.go
@ -72,17 +72,15 @@ func longestCommonPrefix(a, b string) int {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func countParams(path string) uint8 {
|
func countParams(path string) uint16 {
|
||||||
var n uint
|
var n uint
|
||||||
for i := 0; i < len(path); i++ {
|
for i := range []byte(path) {
|
||||||
if path[i] == ':' || path[i] == '*' {
|
switch path[i] {
|
||||||
|
case ':', '*':
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n >= 255 {
|
return uint16(n)
|
||||||
return 255
|
|
||||||
}
|
|
||||||
return uint8(n)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodeType uint8
|
type nodeType uint8
|
||||||
@ -101,7 +99,7 @@ type node struct {
|
|||||||
handlers HandlersChain
|
handlers HandlersChain
|
||||||
priority uint32
|
priority uint32
|
||||||
nType nodeType
|
nType nodeType
|
||||||
maxParams uint8
|
maxParams uint16
|
||||||
wildChild bool
|
wildChild bool
|
||||||
// fullPath string
|
// fullPath string
|
||||||
}
|
}
|
||||||
@ -266,7 +264,7 @@ walk:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search for a wildcard segment and check the name for invalid characters.
|
// 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) {
|
func findWildcard(path string) (wildcard string, i int, valid bool) {
|
||||||
// Find start
|
// Find start
|
||||||
for start, c := range []byte(path) {
|
for start, c := range []byte(path) {
|
||||||
@ -290,7 +288,7 @@ func findWildcard(path string) (wildcard string, i int, valid bool) {
|
|||||||
return "", -1, false
|
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 {
|
for numParams > 0 {
|
||||||
// Find prefix until first wildcard
|
// Find prefix until first wildcard
|
||||||
wildcard, i, valid := findWildcard(path)
|
wildcard, i, valid := findWildcard(path)
|
||||||
|
@ -76,8 +76,8 @@ func checkPriorities(t *testing.T, n *node) uint32 {
|
|||||||
return prio
|
return prio
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMaxParams(t *testing.T, n *node) uint8 {
|
func checkMaxParams(t *testing.T, n *node) uint16 {
|
||||||
var maxParams uint8
|
var maxParams uint16
|
||||||
for i := range n.children {
|
for i := range n.children {
|
||||||
params := checkMaxParams(t, n.children[i])
|
params := checkMaxParams(t, n.children[i])
|
||||||
if params > maxParams {
|
if params > maxParams {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user