New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some loop don't need to transfer to bytes slice and some use the zero… #2572
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c10029a
some loop don't need to transfer to bytes slice and some use the zero…
mask-pp 0d41d35
update gitignore
mask-pp ae39f91
upgrade StringToBytes function
mask-pp 5ff5000
revort unnecessary change
mask-pp 392260a
revort unnecessary change
mask-pp 75021e2
simplify code
mask-pp 8edf824
revort a mistake operation
mask-pp 6d51ad2
update bentchmark report
mask-pp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,10 +205,8 @@ walk: | |
"'") | ||
} | ||
|
||
c := path[0] | ||
|
||
// 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) | ||
n = n.children[0] | ||
n.priority++ | ||
|
@@ -217,7 +215,7 @@ walk: | |
|
||
// Check if a child with the next path byte exists | ||
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) | ||
i = n.incrementChildPrio(i) | ||
n = n.children[i] | ||
|
@@ -226,9 +224,9 @@ walk: | |
} | ||
|
||
// Otherwise insert it | ||
if c != ':' && c != '*' { | ||
if path[0] != ':' && path[0] != '*' { | ||
// []byte for proper unicode char conversion, see #65 | ||
n.indices += bytesconv.BytesToString([]byte{c}) | ||
n.indices += path[0:1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here maybe we should add it, thanks! |
||
child := &node{ | ||
fullPath: fullPath, | ||
} | ||
|
@@ -254,15 +252,15 @@ walk: | |
// 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) { | ||
for start, c := range path { | ||
// A wildcard starts with ':' (param) or '*' (catch-all) | ||
if c != ':' && c != '*' { | ||
continue | ||
} | ||
|
||
// Find end and check for invalid characters | ||
valid = true | ||
for end, c := range []byte(path[start+1:]) { | ||
for end, c := range path[start+1:] { | ||
switch c { | ||
case '/': | ||
return path[start : start+1+end], start, valid | ||
|
@@ -528,7 +526,7 @@ walk: // Outer loop for walking the tree | |
|
||
// No handle found. Check if a handle for this path + a | ||
// trailing slash exists for trailing slash recommendation | ||
for i, c := range []byte(n.indices) { | ||
for i, c := range n.indices { | ||
if c == '/' { | ||
n = n.children[i] | ||
value.tsr = (len(n.path) == 1 && n.handlers != nil) || | ||
|
@@ -745,7 +743,7 @@ walk: // Outer loop for walking the tree | |
// No handle found. | ||
// Try to fix the path by adding a trailing slash | ||
if fixTrailingSlash { | ||
for i, c := range []byte(n.indices) { | ||
for i, c := range n.indices { | ||
if c == '/' { | ||
n = n.children[i] | ||
if (len(n.path) == 1 && n.handlers != nil) || | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the theorem behind this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@panjf2000 based on #2553, we also need to change it.