File tree 1 file changed +9
-12
lines changed
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> {
153
153
self . bytes = remaining;
154
154
Some ( percent_encode_byte ( first_byte) )
155
155
} 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.
168
165
Some ( unsafe { str:: from_utf8_unchecked ( unchanged_slice) } )
169
166
}
170
167
} else {
You can’t perform that action at this time.
0 commit comments