-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Sort: improve the code after recent changes #10647
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
base: main
Are you sure you want to change the base?
Conversation
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
|
||
| for (idx, selector) in settings.selectors.iter().enumerate() { | ||
| let key_index = idx + 1; | ||
| let key_index = idx.saturating_add(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enumerate() itself doesn’t guard against overflow, so guarding only at idx + 1 doesn’t add real safety.
In any case, I think idx.checked_add(1).unwrap() would make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hang on, there is no potential overflow, key_index has the range 1..settings.selectors.len()
They all optimise to the same anyway: https://godbolt.org/z/f4WzhP1vf
| @@ -1800,7 +1803,7 @@ fn emit_debug_warnings( | |||
| show_error!("{}", translate!("sort-warning-simple-byte-comparison")); | |||
|
|
|||
| for (idx, selector) in settings.selectors.iter().enumerate() { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (idx, selector) in settings.selectors.iter().enumerate() { | |
| for (key_index, selector) in (1..).zip(settings.selectors.iter()) { |
after #9848