@@ -953,18 +953,20 @@ fn parse_token<'a>(bytes: &mut Bytes<'a>) -> Result<&'a str> {
953
953
#[ allow( missing_docs) ]
954
954
// WARNING: Exported for internal benchmarks, not fit for public consumption
955
955
pub fn parse_uri < ' a > ( bytes : & mut Bytes < ' a > ) -> Result < & ' a str > {
956
- let start = bytes. pos ( ) ;
957
- simd:: match_uri_vectored ( bytes) ;
958
956
// 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 {
960
959
return Err ( Error :: Token ) ;
961
960
}
961
+ // SAFETY: these bytes have just been matched here above.
962
+ unsafe { bytes. advance ( uri_len) } ;
963
+ let uri_slice = bytes. slice ( ) ;
962
964
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 ) )
968
970
} else {
969
971
Err ( Error :: Token )
970
972
}
@@ -1179,15 +1181,15 @@ fn parse_headers_iter_uninit<'a>(
1179
1181
#[ allow( clippy:: never_loop) ]
1180
1182
// parse header name until colon
1181
1183
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 ( ) ;
1187
1188
// SAFETY: previous call to match_header_name_vectored ensured all bytes are valid
1188
1189
// header name chars, and as such also valid utf-8.
1189
1190
let name = unsafe { str:: from_utf8_unchecked ( bslice) } ;
1190
1191
1192
+ let mut b = next ! ( bytes) ;
1191
1193
if b == b':' {
1192
1194
break ' name name;
1193
1195
}
@@ -1213,6 +1215,7 @@ fn parse_headers_iter_uninit<'a>(
1213
1215
// eat white space between colon and value
1214
1216
' whitespace_after_colon: loop {
1215
1217
b = next ! ( bytes) ;
1218
+
1216
1219
if b == b' ' || b == b'\t' {
1217
1220
bytes. slice ( ) ;
1218
1221
continue ' whitespace_after_colon;
@@ -1239,7 +1242,9 @@ fn parse_headers_iter_uninit<'a>(
1239
1242
' value_lines: loop {
1240
1243
// parse value till EOL
1241
1244
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) } ;
1243
1248
let b = next ! ( bytes) ;
1244
1249
1245
1250
//found_ctl
0 commit comments