Skip to content

Commit 25b7b16

Browse files
authored
Make parse_method return const slice
Performance experiment
1 parent 380f130 commit 25b7b16

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -851,18 +851,16 @@ pub fn parse_method<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
851851
Some(GET) => {
852852
// SAFETY: matched the ASCII string and boundary checked
853853
let method = unsafe {
854-
bytes.advance(4);
855-
let buf = bytes.slice_skip(1);
856-
str::from_utf8_unchecked(buf)
854+
bytes.advance_and_commit(4);
855+
str::from_utf8_unchecked(GET[..GET.len()-1])
857856
};
858857
Ok(Status::Complete(method))
859858
}
860859
Some(POST) if bytes.peek_ahead(4) == Some(b' ') => {
861860
// SAFETY: matched the ASCII string and boundary checked
862861
let method = unsafe {
863-
bytes.advance(5);
864-
let buf = bytes.slice_skip(1);
865-
str::from_utf8_unchecked(buf)
862+
bytes.advance_and_commit(5);
863+
str::from_utf8_unchecked(POST[..])
866864
};
867865
Ok(Status::Complete(method))
868866
}

0 commit comments

Comments
 (0)