@@ -953,18 +953,20 @@ fn parse_token<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
953953#[ allow( missing_docs) ]
954954// WARNING: Exported for internal benchmarks, not fit for public consumption
955955pub fn parse_uri < ' a > ( bytes : & mut Bytes < ' a > ) -> Result < & ' a str > {
956- let start = bytes. pos ( ) ;
957- simd:: match_uri_vectored ( bytes) ;
958956 // URI must have at least one char
959- if bytes. pos ( ) == start {
957+ let uri_len = simd:: match_uri_vectored ( bytes. as_ref ( ) ) ;
958+ if uri_len == 0 {
960959 return Err ( Error :: Token ) ;
961960 }
961+ // SAFETY: these bytes have just been matched here above.
962+ unsafe { bytes. advance ( uri_len) } ;
963+ let uri_slice = bytes. slice ( ) ;
962964
963- if next ! ( bytes) == b' ' {
964- return Ok ( Status :: Complete (
965- // SAFETY: all bytes up till `i ` must have been `is_token` and therefore also utf-8.
966- unsafe { str:: from_utf8_unchecked ( bytes . slice_skip ( 1 ) ) } ,
967- ) ) ;
965+ let space_delim = next ! ( bytes) ;
966+ if space_delim == b' ' {
967+ // SAFETY: all bytes within `uri_slice ` must have been `is_token` and therefore also utf-8.
968+ let uri = unsafe { str:: from_utf8_unchecked ( uri_slice ) } ;
969+ Ok ( Status :: Complete ( uri ) )
968970 } else {
969971 Err ( Error :: Token )
970972 }
@@ -1179,15 +1181,15 @@ fn parse_headers_iter_uninit<'a>(
11791181 #[ allow( clippy:: never_loop) ]
11801182 // parse header name until colon
11811183 let header_name: & str = ' name: loop {
1182- simd:: match_header_name_vectored ( bytes) ;
1183- let mut b = next ! ( bytes) ;
1184-
1185- // SAFETY: previously bumped by 1 with next! -> always safe.
1186- let bslice = unsafe { bytes. slice_skip ( 1 ) } ;
1184+ let len = simd:: match_header_name_vectored ( bytes. as_ref ( ) ) ;
1185+ // SAFETY: these bytes have just been matched here above.
1186+ unsafe { bytes. advance ( len) } ;
1187+ let bslice = bytes. slice ( ) ;
11871188 // SAFETY: previous call to match_header_name_vectored ensured all bytes are valid
11881189 // header name chars, and as such also valid utf-8.
11891190 let name = unsafe { str:: from_utf8_unchecked ( bslice) } ;
11901191
1192+ let mut b = next ! ( bytes) ;
11911193 if b == b':' {
11921194 break ' name name;
11931195 }
@@ -1213,6 +1215,7 @@ fn parse_headers_iter_uninit<'a>(
12131215 // eat white space between colon and value
12141216 ' whitespace_after_colon: loop {
12151217 b = next ! ( bytes) ;
1218+
12161219 if b == b' ' || b == b'\t' {
12171220 bytes. slice ( ) ;
12181221 continue ' whitespace_after_colon;
@@ -1239,7 +1242,9 @@ fn parse_headers_iter_uninit<'a>(
12391242 ' value_lines: loop {
12401243 // parse value till EOL
12411244
1242- simd:: match_header_value_vectored ( bytes) ;
1245+ let len = simd:: match_header_value_vectored ( bytes. as_ref ( ) ) ;
1246+ // SAFETY: these bytes have just been matched here above.
1247+ unsafe { bytes. advance ( len) } ;
12431248 let b = next ! ( bytes) ;
12441249
12451250 //found_ctl
0 commit comments