From 6ed0f08cd2cd3129bfc44dfe11800439b628f39b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 13 Jan 2026 22:46:08 +0100 Subject: [PATCH] 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. --- src/uu/sort/src/sort.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 18ceb546d..53c50f187 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -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 {