Skip to content

Commit

Permalink
Use is_ascii_digit() instead of manual range check
Browse files Browse the repository at this point in the history
  • Loading branch information
hesampakdaman committed May 19, 2024
1 parent 41b5c75 commit 80e3d8a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn parse_float(bytes: &[u8]) -> i32 {
let neg = (bytes[0] == b'-') as usize;
let sgn = 1 - 2 * neg as i32;
let res = bytes.iter().skip(neg).fold(0, |acc, &byte| {
let is_digit = (b'0' <= byte && byte <= b'9') as i32;
let is_digit = byte.is_ascii_digit() as i32;
let digit = (byte as i32).wrapping_sub(b'0' as i32);
acc * (10 * is_digit + (1 - is_digit)) + digit * is_digit
});
Expand Down

0 comments on commit 80e3d8a

Please sign in to comment.