Skip to content

Commit

Permalink
Auto merge of rust-lang#81427 - klensy:eat-digits, r=m-ou-se
Browse files Browse the repository at this point in the history
simplify eat_digits

Simplify eat_digits by checking values in iterator, plus decrease function size, by returning unchecked slices.

https://godbolt.org/z/cxjav4
  • Loading branch information
bors committed Feb 20, 2021
2 parents b75baad + ec09d7f commit da5f7f1
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions library/core/src/num/dec2flt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ pub fn parse_decimal(s: &str) -> ParseResult<'_> {

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

/// Exponent extraction and error checking.
Expand Down

0 comments on commit da5f7f1

Please sign in to comment.