diff --git a/src/iter.rs b/src/iter.rs index 85d9e79..2dde2e7 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -40,19 +40,6 @@ impl<'a> Bytes<'a> { None } } - - #[inline] - pub fn peek_ahead(&self, n: usize) -> Option { - // 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 { diff --git a/src/lib.rs b/src/lib.rs index 4ccd783..1eb9724 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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);