-
Notifications
You must be signed in to change notification settings - Fork 13k
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
to_digit simplification (less jumps) #85630
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
There bultin diff function in godbolt: https://godbolt.org/z/jMsv6dKh8 |
This comment has been minimized.
This comment has been minimized.
Good point. Have flicked the code around so the red / green works in the diff and optimised the to upper case: |
This comment has been minimized.
This comment has been minimized.
I don't believe this implementation is correct. E.g. it will return Some other issues: A is Some(17) in base 36, a is None in base 36, even though both should be returning a (Can you add cases like these as tests, please?) |
Sorry jumped strate to the bench skipping tests - too much excitement. |
This comment has been minimized.
This comment has been minimized.
Ok am really happy with that: https://godbolt.org/z/n77njGz3T |
@nagisa is this all looking good now from your perspective? |
Squash the commits, please. Otherwise looks pretty nice. |
Can you update benches in first message with latest version? |
r? @nagisa |
will do |
Have updated the benchmarks. I'm not really happy with the benchmark definitions though I have failed to come up with an alternative that has less benchmark noise. |
bcea845
to
9c3d81e
Compare
Ok @nagisa think it is good to go. |
@bors r+ |
📌 Commit 9c3d81e has been approved by |
@gilescope You can use cargo-benchcmp to compare bench results in more simple way. |
☀️ Test successful - checks-actions |
I just realised we might be able to make use of the fact that changing case in ascii is easy to help simplify to_digit some more.
It looks a bit cleaner and it looks like it's less jumps and there's less instructions in the generated assembly:
https://godbolt.org/z/84Erh5dhz
The benchmarks don't really tell me much. Maybe a slight improvement on the var radix.
Before:
After:
I removed the likely as it resulted in a few less instructions. (It's not been in there long - I added it in the last to_digit iteration).