From 26265319c7d04306ccdf60e50580e3778f5e9134 Mon Sep 17 00:00:00 2001 From: gabriel-doriath-dohler Date: Sun, 15 May 2022 23:59:59 +0000 Subject: [PATCH] Rename `eq_ignore_case` to `starts_with_ignore_case` The method doesn't test for equality. It tests if the object starts with a given byte array, so its name is confusing. --- library/core/src/num/dec2flt/common.rs | 2 +- library/core/src/num/dec2flt/parse.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/num/dec2flt/common.rs b/library/core/src/num/dec2flt/common.rs index 247123737df42..17957d7e77048 100644 --- a/library/core/src/num/dec2flt/common.rs +++ b/library/core/src/num/dec2flt/common.rs @@ -36,7 +36,7 @@ pub(crate) trait ByteSlice: AsRef<[u8]> { } /// Check if self starts with u with a case-insensitive comparison. - fn eq_ignore_case(&self, u: &[u8]) -> bool { + fn starts_with_ignore_case(&self, u: &[u8]) -> bool { debug_assert!(self.as_ref().len() >= u.len()); let iter = self.as_ref().iter().zip(u.iter()); let d = iter.fold(0, |i, (&x, &y)| i | (x ^ y)); diff --git a/library/core/src/num/dec2flt/parse.rs b/library/core/src/num/dec2flt/parse.rs index fa677bf512395..1a90e0d206fd7 100644 --- a/library/core/src/num/dec2flt/parse.rs +++ b/library/core/src/num/dec2flt/parse.rs @@ -207,12 +207,12 @@ pub fn parse_number(s: &[u8], negative: bool) -> Option { /// Parse a partial representation of a special, non-finite float. fn parse_partial_inf_nan(s: &[u8]) -> Option<(F, usize)> { fn parse_inf_rest(s: &[u8]) -> usize { - if s.len() >= 8 && s[3..].as_ref().eq_ignore_case(b"inity") { 8 } else { 3 } + if s.len() >= 8 && s[3..].as_ref().starts_with_ignore_case(b"inity") { 8 } else { 3 } } if s.len() >= 3 { - if s.eq_ignore_case(b"nan") { + if s.starts_with_ignore_case(b"nan") { return Some((F::NAN, 3)); - } else if s.eq_ignore_case(b"inf") { + } else if s.starts_with_ignore_case(b"inf") { return Some((F::INFINITY, parse_inf_rest(s))); } }