-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Optimize string operations throughout the codebase #86235
Conversation
a824524
to
6d8ce4b
Compare
It appears the changes breaks some code, see the broken doc generation |
287214b
to
f1a6d94
Compare
Unit tests show their worth, let's see what's broken with your implementation of the string methods, will do some looking into it tomorrow if you haven't solved 🙂 |
f1a6d94
to
fb938ed
Compare
I can't figure it out from just looking 😞 I can debug more thoroughly tomorrow. |
These are not the same for
These are not the same for
The mentioned PR: #80824 (please link next time you refer to some other PR). Lines 2975 to 2995 in 2d0ee20
Same for other methods (like left/right ). Note it's already like that e.g. in find :Lines 3002 to 3004 in 2d0ee20
Regarding code simplification these can be done for sure:
I find these better readability-wise, plus it gets rid of redundant |
I'd say that unless things are in a very performance critical area readability trumps performance, I'm in favor of the obvious ones like |
Hmpf, so my old PR only did ones with I know that I think I'll abandon the idea because of that.
The old left/right were calling substr() directly, so it seems fair to me. Unless there is a notable penalty for going through an extra function that I don't know of. |
I'd say to remove the potentially ambiguous cases and see if that resolves the CI, that being the The |
524f5ae
to
520a728
Compare
520a728
to
3eebd7f
Compare
What the heck, is the logic of I'm tired, will investigate this later. |
3eebd7f
to
d88ffbe
Compare
I'll leave this idea at peace for now. |
A more manageable version of #82412 that does more types of optimizations, but only applies them to user-exposed classes (so the total volume of them is a lot less). No benchmarking done.
For reference, most of them are like:
s.substr(0, x)
->s.left(x)
s.substr(0, s.length() - x)
->s.left(-x)
s.substr(x, s.length())
->s.right(-x)
s.substr(x, s.length() - x)
->s.right(-x)
I think all of these are equivalent 100% of the time, but they are ~15% faster (benchmarking from my PR that optimized left and right).