-
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/compile: Optimize three-way string comparisons #31187
Comments
Currently we break string comparison ops into runtime calls during walk. |
This would be another possible use for an rtcall SSA pass: #24926 But it’d be better indeed to leave these unlowered until much later. Which would require making it reasonable to manipulate and insert calls in SSA. Which is yet another reason to move parameter and result handling into ssa ops instead of SP writes and reads. (I’m pretty sure I’ve written this paragraph a dozen times. I should just go do it.) |
This would also be nice so that type key struct {
f1, f2, f3 string
}
func (k key) Compare(o key) int {
if c := strings.Compare(k.f1, o.f1); c != 0 {
return c
}
if c := strings.Compare(k.f2, o.f2); c != 0 {
return c
}
if c := strings.Compare(k.f3, o.f3); c != 0 {
return c
}
return 0
} I mean, I could always implement my own strCompare helper func if |
Change https://go.dev/cl/531997 mentions this issue: |
It is done for #61725 |
Technically this issue isn't done, but since people can now call |
As shown in
strings.Compare
's source code, three-way string comparisons can be optimized.A few use cases are:
For the last use case my benchmark showed a over 10% improvement by using
bytes.Compare
instaed ofstrings.Compare
.The text was updated successfully, but these errors were encountered: