-
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/vet: vet should recommend to use operators instead of strings.Compare
to compare strings
#50209
Comments
related: #50167 |
I think vet is more for correctness, not for optimizations. Also, as you mentioned, there are valid uses of strings.Compare. I'm not sure vet should do this. |
Here are the vet inclusion criteria https://github.com/golang/go/blob/master/src/cmd/vet/README This suggestion plausibly fails the "correctness" criteria:
An argument might be that this is a not a style suggestion and is instead an efficiency suggestion. My personal inclination is that this qualifies as 'identifying an alternative correct approach to a situation'. I am curious how others feel about this though. Other thoughts:
|
I agree that this is not a suitable check for cmd/vet. |
This seems like an ideal candidate for a tool like gocritic |
OK, I created an issue in the go-critic project: go-critic/go-critic#1167 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
warning that
strings.Compare(x, y) == 0
is slower thanx == y
for some cases.By the current(sorry, there are still some cases thestrings.Compare
implementation, all calls to this functions should be warned.strings.Compare
way is more performant)What did you see instead?
Nothing outputted.
The text was updated successfully, but these errors were encountered: