@@ -953,20 +953,18 @@ 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) ;
956958 // URI must have at least one char
957- let uri_len = simd:: match_uri_vectored ( bytes. as_ref ( ) ) ;
958- if uri_len == 0 {
959+ if bytes. pos ( ) == start {
959960 return Err ( Error :: Token ) ;
960961 }
961- // SAFETY: these bytes have just been matched here above.
962- unsafe { bytes. advance ( uri_len) } ;
963- let uri_slice = bytes. slice ( ) ;
964962
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 ) )
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+ ) ) ;
970968 } else {
971969 Err ( Error :: Token )
972970 }
@@ -1181,15 +1179,15 @@ fn parse_headers_iter_uninit<'a>(
11811179 #[ allow( clippy:: never_loop) ]
11821180 // parse header name until colon
11831181 let header_name: & str = ' name: loop {
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 ( ) ;
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 ) } ;
11881187 // SAFETY: previous call to match_header_name_vectored ensured all bytes are valid
11891188 // header name chars, and as such also valid utf-8.
11901189 let name = unsafe { str:: from_utf8_unchecked ( bslice) } ;
11911190
1192- let mut b = next ! ( bytes) ;
11931191 if b == b':' {
11941192 break ' name name;
11951193 }
@@ -1215,7 +1213,6 @@ fn parse_headers_iter_uninit<'a>(
12151213 // eat white space between colon and value
12161214 ' whitespace_after_colon: loop {
12171215 b = next ! ( bytes) ;
1218-
12191216 if b == b' ' || b == b'\t' {
12201217 bytes. slice ( ) ;
12211218 continue ' whitespace_after_colon;
@@ -1242,9 +1239,7 @@ fn parse_headers_iter_uninit<'a>(
12421239 ' value_lines: loop {
12431240 // parse value till EOL
12441241
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) } ;
1242+ simd:: match_header_value_vectored ( bytes) ;
12481243 let b = next ! ( bytes) ;
12491244
12501245 //found_ctl
0 commit comments