mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 06:42:10 +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
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user