Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
RoDmitry committed Nov 28, 2023
1 parent ecf1955 commit 6117a0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/linker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ pub trait Parser<T: ParserPos<T>>: Sized {
if *s.first().ok_or(AtoiSimdError::Empty)? == b'+' {
i = 1;
}
while i + 1 < s.len() {
if *s.get_safe_unchecked(i) != b'0' {
break;
}
let len_1 = s.len().saturating_sub(1);
while i < len_1 && *s.get_safe_unchecked(i) == b'0' {
i += 1;
}

Expand Down Expand Up @@ -120,10 +118,8 @@ fn atoi_simd_parse_skipped_signed<T: ParserPos<T> + ParserNeg<T>>(
}
_ => {}
};
while i + 1 < s.len() {
if *s.get_safe_unchecked(i) != b'0' {
break;
}
let len_1 = s.len().saturating_sub(1);
while i < len_1 && *s.get_safe_unchecked(i) == b'0' {
i += 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ fn test_parse_skipped() {
let tmp = parse_skipped::<i128>(b"-000000000000000000000000012345678901234567890").unwrap();
assert_eq!(tmp, -12345678901234567890_i128);

assert!(parse_skipped::<u64>(b"").is_err());

// Zeroes.
assert_eq!(parse_skipped::<i8>(b"0"), Ok(0));
assert_eq!(parse_skipped::<i8>(b"-0"), Ok(0));
Expand Down

0 comments on commit 6117a0d

Please sign in to comment.