-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2572 +/- ##
==========================================
- Coverage 98.48% 98.47% -0.01%
==========================================
Files 41 41
Lines 1974 1973 -1
==========================================
- Hits 1944 1943 -1
Misses 17 17
Partials 13 13
Continue to review full report at Codecov.
|
tree.go
Outdated
@@ -611,7 +611,7 @@ walk: // Outer loop for walking the tree | |||
if rb[0] != 0 { | |||
// Old rune not finished | |||
idxc := rb[0] | |||
for i, c := range []byte(n.indices) { | |||
for i, c := range bytesconv.StringToBytes(n.indices) { |
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.
why add it here, but not add before?
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.
loop string type and don't cpompare with a byte don't need to do it, but that loop used so change to slice is necessary, and use StringToBytes will be better. Thanks!
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.
thanks. using local var save the result of StringToBytes
?
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.
I believe it's unnecessary to call bytesconv.StringToBytes
in a for range
loop, there is a compiler optimization that will avoid the copies, see https://github.com/golang/go/wiki/CompilerOptimizations#range-over-bytes.
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.
ok, i see thanks.
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.
thanks. using local var save the result of
StringToBytes
?
that kind of change is not necessary.
@appleboy @panjf2000 please help review the pull request, thanks! |
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) | ||
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len | ||
return b | ||
func StringToBytes(s string) []byte { |
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.
unit test error:
|
sorry, it's a mistake, should use utf8 type but not the byte. |
// []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 comment
The reason will be displayed to describe this comment to others. Learn more.
here maybe we should add it, thanks!
@appleboy please review the pull request, thanks! |
@mask-pp Please provide the benchmark report? |
ok, Is about StringToBytes change or others? |
Provide the benchmark result. See https://github.com/gin-gonic/gin/blob/master/BENCHMARKS.md |
any update? Thanks |
already updated bentchmark report, please check. thanks! |
@mask-pp upload the benchmark in the comment not update the markdown file |
|
why closed? |
some loop don't need to transfer to bytes slice and some use the zero copy will much better.