Skip to content

Commit da5f7f1

Browse files
committed
Auto merge of #81427 - klensy:eat-digits, r=m-ou-se
simplify eat_digits Simplify eat_digits by checking values in iterator, plus decrease function size, by returning unchecked slices. https://godbolt.org/z/cxjav4
2 parents b75baad + ec09d7f commit da5f7f1

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

library/core/src/num/dec2flt/parse.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,8 @@ pub fn parse_decimal(s: &str) -> ParseResult<'_> {
8080

8181
/// Carves off decimal digits up to the first non-digit character.
8282
fn eat_digits(s: &[u8]) -> (&[u8], &[u8]) {
83-
let mut i = 0;
84-
while i < s.len() && b'0' <= s[i] && s[i] <= b'9' {
85-
i += 1;
86-
}
87-
(&s[..i], &s[i..])
83+
let pos = s.iter().position(|c| !c.is_ascii_digit()).unwrap_or(s.len());
84+
s.split_at(pos)
8885
}
8986

9087
/// Exponent extraction and error checking.

0 commit comments

Comments
 (0)