@@ -953,20 +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) ;
958- let end = bytes. pos ( ) ;
959-
960- if next ! ( bytes) == b' ' {
961- // URI must have at least one char
962- if end == start {
963- return Err ( Error :: Token ) ;
964- }
956+ // URI must have at least one char
957+ let uri_len = simd:: match_uri_vectored ( bytes. as_ref ( ) ) ;
958+ if uri_len == 0 {
959+ return Err ( Error :: Token ) ;
960+ }
961+ // SAFETY: these bytes have just been matched here above.
962+ unsafe { bytes. advance ( uri_len) } ;
963+ let uri_slice = bytes. slice ( ) ;
965964
966- return Ok ( Status :: Complete (
967- // SAFETY: all bytes up till `i` must have been `is_token` and therefore also utf-8.
968- unsafe { str:: from_utf8_unchecked ( bytes. slice_skip ( 1 ) ) } ,
969- ) ) ;
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) )
970970 } else {
971971 Err ( Error :: Token )
972972 }
@@ -1181,15 +1181,15 @@ fn parse_headers_iter_uninit<'a>(
11811181 #[ allow( clippy:: never_loop) ]
11821182 // parse header name until colon
11831183 let header_name: & str = ' name: loop {
1184- simd:: match_header_name_vectored ( bytes) ;
1185- let mut b = next ! ( bytes) ;
1186-
1187- // SAFETY: previously bumped by 1 with next! -> always safe.
1188- 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 ( ) ;
11891188 // SAFETY: previous call to match_header_name_vectored ensured all bytes are valid
11901189 // header name chars, and as such also valid utf-8.
11911190 let name = unsafe { str:: from_utf8_unchecked ( bslice) } ;
11921191
1192+ let mut b = next ! ( bytes) ;
11931193 if b == b':' {
11941194 break ' name name;
11951195 }
@@ -1215,6 +1215,7 @@ fn parse_headers_iter_uninit<'a>(
12151215 // eat white space between colon and value
12161216 ' whitespace_after_colon: loop {
12171217 b = next ! ( bytes) ;
1218+
12181219 if b == b' ' || b == b'\t' {
12191220 bytes. slice ( ) ;
12201221 continue ' whitespace_after_colon;
@@ -1241,7 +1242,9 @@ fn parse_headers_iter_uninit<'a>(
12411242 ' value_lines: loop {
12421243 // parse value till EOL
12431244
1244- 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) } ;
12451248 let b = next ! ( bytes) ;
12461249
12471250 //found_ctl
0 commit comments