Skip to content

Commit

Permalink
Inline peek_ahead to fix 186 and remove iter::peek_ahead as it is now…
Browse files Browse the repository at this point in the history
… unused.
  • Loading branch information
hkBst committed Oct 22, 2024
1 parent 97c7e6e commit c0ae7fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
13 changes: 0 additions & 13 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ impl<'a> Bytes<'a> {
None
}
}

#[inline]
pub fn peek_ahead(&self, n: usize) -> Option<u8> {
// SAFETY: obtain a potentially OOB pointer that is later compared against the `self.end`
// pointer.
let ptr = self.cursor.wrapping_add(n);
if ptr < self.end {
// SAFETY: bounds checked pointer dereference is safe
Some(unsafe { *ptr })
} else {
None
}
}

#[inline]
pub fn peek_n<'b: 'a, U: TryFrom<&'a [u8]>>(&'b self, n: usize) -> Option<U> {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,9 @@ pub fn parse_method<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
};
Ok(Status::Complete(method))
}
Some(POST) if bytes.peek_ahead(4) == Some(b' ') => {
Some(POST)
if (bytes.cursor.add(4) < bytes.end).then(|| *bytes.cursor.add(4)) == Some(b' ') =>

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test beta on ubuntu-latest

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test nightly on ubuntu-latest

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test nightly on ubuntu-latest

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test stable on ubuntu-latest

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test stable on ubuntu-latest

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / check x86

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / check x86

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / check x86

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on nightly

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on nightly

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on nightly

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2,+avx2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / SIMD +sse4.2 on beta

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

no method named `then` found for type `bool` in the current scope

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (x64)

field `cursor` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (aarch64)

field `end` of struct `iter::Bytes` is private

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (aarch64)

no method named `then` found for type `bool` in the current scope

Check failure on line 857 in src/lib.rs

View workflow job for this annotation

GitHub Actions / msrv (aarch64)

field `cursor` of struct `iter::Bytes` is private
{
// SAFETY: matched the ASCII string and boundary checked
let method = unsafe {
bytes.advance(5);
Expand Down

0 comments on commit c0ae7fb

Please sign in to comment.