mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sort: refactor ordering_incompatible to use early returns
Simplify the function by computing mode_count directly and using early returns instead of accumulating a counter with nested if statements.
This commit is contained in:
+14
-15
@@ -511,23 +511,22 @@ fn ordering_incompatible(
|
||||
dictionary_order: bool,
|
||||
ignore_non_printing: bool,
|
||||
) -> bool {
|
||||
let mut count = 0;
|
||||
if flags.numeric {
|
||||
count += 1;
|
||||
let mode_count = u8::from(flags.numeric)
|
||||
+ u8::from(flags.general_numeric)
|
||||
+ u8::from(flags.human_numeric)
|
||||
+ u8::from(flags.month);
|
||||
|
||||
// Multiple numeric/month modes are incompatible
|
||||
if mode_count > 1 {
|
||||
return true;
|
||||
}
|
||||
if flags.general_numeric {
|
||||
count += 1;
|
||||
|
||||
// A numeric/month mode combined with version/random/dictionary/ignore_non_printing is incompatible
|
||||
if mode_count == 1 {
|
||||
return flags.version || flags.random || dictionary_order || ignore_non_printing;
|
||||
}
|
||||
if flags.human_numeric {
|
||||
count += 1;
|
||||
}
|
||||
if flags.month {
|
||||
count += 1;
|
||||
}
|
||||
if flags.version || flags.random || dictionary_order || ignore_non_printing {
|
||||
count += 1;
|
||||
}
|
||||
count > 1
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn incompatible_options_error(opts: &str) -> Box<dyn UError> {
|
||||
|
||||
Reference in New Issue
Block a user