-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/gc: optimized range over []byte(string) #2204
Labels
Comments
Related, mentioned by Gustavo Niemeyer here: https://groups.google.com/group/golang-dev/msg/bc0e89aadc748577 ` More seriously, why doing if strings.EqualsBytes(s, b) { ... } rather than if string(b) == s { ... } If this is just about saving the conversion, should this be done by the compiler? ` |
I am very reluctant to make optimizations like this. It makes it very hard to tell when something is expensive or not. If we did the suggested optimization, then for _, _ := range []byte(s) { would be cheap, while b := []byte(s) for _, _ := range b { would be expensive. Or maybe it could be cheap too, but b := []byte(s) for i, _ := range b { b[i] = 1 } would be expensive. You comment out a line and boom, expense happens. I don't see a way around this, and we are probably going to get forced to make optimizations like this. (Escape analysis is one.) But I am still a bit uncomfortable. Owner changed to @rsc. Status changed to Accepted. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: