File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -153,18 +153,15 @@ impl<'a> Iterator for PercentEncode<'a> {
153153 self . bytes = remaining;
154154 Some ( percent_encode_byte ( first_byte) )
155155 } else {
156- // The unsafe blocks here are appropriate because the bytes are
157- // confirmed as a subset of UTF-8 in should_percent_encode.
158- for ( i, & byte) in remaining. iter ( ) . enumerate ( ) {
159- if self . ascii_set . should_percent_encode ( byte) {
160- // 1 for first_byte + i for previous iterations of this loop
161- let ( unchanged_slice, remaining) = self . bytes . split_at ( 1 + i) ;
162- self . bytes = remaining;
163- return Some ( unsafe { str:: from_utf8_unchecked ( unchanged_slice) } ) ;
164- }
165- }
166- let unchanged_slice = self . bytes ;
167- self . bytes = & [ ] [ ..] ;
156+ let ( unchanged_slice, remaining) = self . bytes . split_at (
157+ // 1 for the first byte + rest in remaining
158+ 1 + remaining
159+ . iter ( )
160+ . position ( |& byte| self . ascii_set . should_percent_encode ( byte) )
161+ . unwrap_or ( remaining. len ( ) ) ,
162+ ) ;
163+ self . bytes = remaining;
164+ // SAFETY: bytes are confirmed as a subset of UTF-8 in should_percent_encode.
168165 Some ( unsafe { str:: from_utf8_unchecked ( unchanged_slice) } )
169166 }
170167 } else {
You can’t perform that action at this time.
0 commit comments