Skip to content

Commit

Permalink
Add optimization for single wildcard child
Browse files Browse the repository at this point in the history
  • Loading branch information
rw-access committed Apr 1, 2021
1 parent 32b2982 commit 5134779
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions tree.go
Expand Up @@ -407,22 +407,25 @@ walk: // Outer loop for walking the tree
if path[:len(prefix)] == prefix {
path = path[len(prefix):]

// Try all the non-wildcard children first by matching the indices
idxc := path[0]
for i, c := range []byte(n.indices) {
if c == idxc {
n = n.children[i]
continue walk
// skip over the indices+tsr check if there's exactly 1 child and its a param
if !(n.wildChild && len(n.children) == 1) {
// Try all the non-wildcard children first by matching the indices
idxc := path[0]
for i, c := range []byte(n.indices) {
if c == idxc {
n = n.children[i]
continue walk
}
}
}

// If there is no wildcard pattern, recommend a redirection
if !n.wildChild {
// Nothing found.
// We can recommend to redirect to the same URL without a
// trailing slash if a leaf exists for that path.
value.tsr = (path == "/" && n.handlers != nil)
return
// If there is no wildcard pattern, recommend a redirection
if !n.wildChild {
// Nothing found.
// We can recommend to redirect to the same URL without a
// trailing slash if a leaf exists for that path.
value.tsr = (path == "/" && n.handlers != nil)
return
}
}

// Handle wildcard child, which is always at the end of the array
Expand Down

0 comments on commit 5134779

Please sign in to comment.