Skip to content

Commit

Permalink
fix(token): Be consistent on take_until("")
Browse files Browse the repository at this point in the history
We aren't consistent on empty buffers between `simd` and not.

Fixes #489
  • Loading branch information
epage committed Feb 28, 2024
1 parent f417ec2 commit 9d50921
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,7 @@ fn memchr3(token: (u8, u8, u8), slice: &[u8]) -> Option<usize> {
#[inline(always)]
fn memmem(slice: &[u8], literal: &[u8]) -> Option<crate::lib::std::ops::Range<usize>> {
match literal.len() {
0 => Some(0..0),
1 => memchr(literal[0], slice).map(|i| i..i + 1),

Check warning on line 3483 in src/stream/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/stream/mod.rs#L3483

Added line #L3483 was not covered by tests
_ => memmem_(slice, literal),
}
Expand All @@ -3487,6 +3488,7 @@ fn memmem(slice: &[u8], literal: &[u8]) -> Option<crate::lib::std::ops::Range<us
#[inline(always)]
fn memmem2(slice: &[u8], literal: (&[u8], &[u8])) -> Option<crate::lib::std::ops::Range<usize>> {
match (literal.0.len(), literal.1.len()) {
(0, _) | (_, 0) => Some(0..0),

Check warning on line 3491 in src/stream/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/stream/mod.rs#L3491

Added line #L3491 was not covered by tests
(1, 1) => memchr2((literal.0[0], literal.1[0]), slice).map(|i| i..i + 1),
_ => memmem2_(slice, literal),

Check warning on line 3493 in src/stream/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/stream/mod.rs#L3493

Added line #L3493 was not covered by tests
}
Expand All @@ -3498,6 +3500,7 @@ fn memmem3(
literal: (&[u8], &[u8], &[u8]),
) -> Option<crate::lib::std::ops::Range<usize>> {
match (literal.0.len(), literal.1.len(), literal.2.len()) {
(0, _, _) | (_, 0, _) | (_, _, 0) => Some(0..0),
(1, 1, 1) => memchr3((literal.0[0], literal.1[0], literal.2[0]), slice).map(|i| i..i + 1),
_ => memmem3_(slice, literal),

Check warning on line 3505 in src/stream/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/stream/mod.rs#L3502-L3505

Added lines #L3502 - L3505 were not covered by tests
}
Expand Down
6 changes: 0 additions & 6 deletions src/token/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ fn complete_take_until_empty() {
fn take_until_empty(i: &str) -> IResult<&str, &str> {
take_until(0, "").parse_peek(i)
}
#[cfg(not(feature = "simd"))]
assert_eq!(
take_until_empty(""),
Err(ErrMode::Backtrack(error_position!(&"", ErrorKind::Slice)))
);
#[cfg(feature = "simd")]
assert_eq!(take_until_empty(""), Ok(("", "")));
assert_eq!(take_until_empty("end"), Ok(("end", "")));
}
Expand Down

0 comments on commit 9d50921

Please sign in to comment.