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:
Sylvestre Ledru
2026-01-13 22:46:08 +01:00
parent db1d57c18b
commit 6ed0f08cd2
+14 -15
View File
@@ -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> {