From 67b83647ac41515f762506211ec6390c19fa0b2d Mon Sep 17 00:00:00 2001 From: Michael Debertol Date: Tue, 1 Jun 2021 18:09:39 +0200 Subject: [PATCH] sort: simplify handling of negative zeros We can simply parse the sign of negative zero as positive, instead of handling the comparison of zeros differently. --- src/uu/sort/src/numeric_str_cmp.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/uu/sort/src/numeric_str_cmp.rs b/src/uu/sort/src/numeric_str_cmp.rs index 461f72670..8cd3faab2 100644 --- a/src/uu/sort/src/numeric_str_cmp.rs +++ b/src/uu/sort/src/numeric_str_cmp.rs @@ -107,7 +107,7 @@ impl NumInfo { } else { ( NumInfo { - sign: if had_digit { sign } else { Sign::Positive }, + sign: Sign::Positive, exponent: 0, }, if had_digit { @@ -147,7 +147,7 @@ impl NumInfo { } else { ( NumInfo { - sign: if had_digit { sign } else { Sign::Positive }, + sign: Sign::Positive, exponent: 0, }, if had_digit { @@ -187,11 +187,7 @@ impl NumInfo { pub fn numeric_str_cmp((a, a_info): (&str, &NumInfo), (b, b_info): (&str, &NumInfo)) -> Ordering { // check for a difference in the sign if a_info.sign != b_info.sign { - return if a.is_empty() && b.is_empty() { - Ordering::Equal - } else { - a_info.sign.cmp(&b_info.sign) - }; + return a_info.sign.cmp(&b_info.sign); } // check for a difference in the exponent