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 7b83de1
Show file tree
Hide file tree
Showing 2 changed files with 5 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
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,11 @@ 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 unsafe {
(bytes.cursor.add(4) < bytes.end).then(|| *bytes.cursor.add(4)) == Some(b' ')
} =>
{
// SAFETY: matched the ASCII string and boundary checked
let method = unsafe {
bytes.advance(5);
Expand Down

0 comments on commit 7b83de1

Please sign in to comment.