-
-
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?
Changes from all commits
34237cb
ef3a503
1aadae3
d8528e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,3 +243,7 @@ Hijri | |
| Nowruz | ||
| charmap | ||
| hijri | ||
|
|
||
| TERA | ||
| GIGA | ||
| PETA | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,9 @@ use uucore::i18n::collator::locale_cmp; | |
| use uucore::i18n::decimal::locale_decimal_separator; | ||
| use uucore::line_ending::LineEnding; | ||
| use uucore::parser::num_parser::{ExtendedParser, ExtendedParserError}; | ||
| #[cfg(test)] | ||
| use uucore::parser::parse_size::{EXA, TERA}; | ||
| use uucore::parser::parse_size::{GIGA, KILO, MEGA}; | ||
| use uucore::parser::parse_size::{ParseSizeError, Parser}; | ||
| use uucore::parser::shortcut_value_parser::ShortcutValueParser; | ||
| use uucore::posix::{MODERN, TRADITIONAL}; | ||
|
|
@@ -125,9 +128,9 @@ const POSITIVE: &u8 = &b'+'; | |
| // The automatic buffer heuristics clamp to this range to avoid | ||
| // over-committing memory on constrained systems while still keeping | ||
| // reasonably large chunks for typical workloads. | ||
| const MIN_AUTOMATIC_BUF_SIZE: usize = 512 * 1024; // 512 KiB | ||
| const FALLBACK_AUTOMATIC_BUF_SIZE: usize = 32 * 1024 * 1024; // 32 MiB | ||
| const MAX_AUTOMATIC_BUF_SIZE: usize = 1024 * 1024 * 1024; // 1 GiB | ||
| const MIN_AUTOMATIC_BUF_SIZE: usize = 512 * KILO; // 512 KiB | ||
| const FALLBACK_AUTOMATIC_BUF_SIZE: usize = 32 * MEGA; // 32 MiB | ||
| const MAX_AUTOMATIC_BUF_SIZE: usize = GIGA; // 1 GiB | ||
|
|
||
| #[derive(Debug, Error)] | ||
| pub enum SortError { | ||
|
|
@@ -1800,7 +1803,7 @@ fn emit_debug_warnings( | |
| show_error!("{}", translate!("sort-warning-simple-byte-comparison")); | ||
|
|
||
| for (idx, selector) in settings.selectors.iter().enumerate() { | ||
| let key_index = idx + 1; | ||
| let key_index = idx.saturating_add(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In any case, I think
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hang on, there is no potential overflow, They all optimise to the same anyway: https://godbolt.org/z/f4WzhP1vf |
||
| if let Some(legacy) = legacy_warnings | ||
| .iter() | ||
| .find(|warning| warning.key_index == Some(key_index)) | ||
|
|
@@ -3184,24 +3187,24 @@ mod tests { | |
| fn test_parse_byte_count() { | ||
| let valid_input = [ | ||
| ("0", 0), | ||
| ("50K", 50 * 1024), | ||
| ("50k", 50 * 1024), | ||
| ("1M", 1024 * 1024), | ||
| ("100M", 100 * 1024 * 1024), | ||
| ("50K", 50 * KILO), | ||
| ("50k", 50 * KILO), | ||
| ("1M", MEGA), | ||
| ("100M", 100 * MEGA), | ||
| #[cfg(not(target_pointer_width = "32"))] | ||
| ("1000G", 1000 * 1024 * 1024 * 1024), | ||
| ("1000G", 1000 * GIGA), | ||
| #[cfg(not(target_pointer_width = "32"))] | ||
| ("10T", 10 * 1024 * 1024 * 1024 * 1024), | ||
| ("10T", 10 * TERA), | ||
| ("1b", 1), | ||
| ("1024b", 1024), | ||
| ("1024Mb", 1024 * 1024 * 1024), // NOTE: This might not be how GNU `sort` behaves for 'Mb' | ||
| ("1", 1024), // K is default | ||
| ("50", 50 * 1024), | ||
| ("K", 1024), | ||
| ("k", 1024), | ||
| ("m", 1024 * 1024), | ||
| ("1024b", KILO), | ||
| ("1024Mb", KILO * MEGA), // NOTE: This might not be how GNU `sort` behaves for 'Mb' | ||
| ("1", KILO), // K is default | ||
| ("50", 50 * KILO), | ||
| ("K", KILO), | ||
| ("k", KILO), | ||
| ("m", MEGA), | ||
| #[cfg(not(target_pointer_width = "32"))] | ||
| ("E", 1024 * 1024 * 1024 * 1024 * 1024 * 1024), | ||
| ("E", EXA), | ||
| ]; | ||
| for (input, expected_output) in &valid_input { | ||
| assert_eq!( | ||
|
|
||
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.