File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -289,7 +289,9 @@ impl str {
289
289
let to_utf8_len = to. as_bytes ( ) . len ( ) ;
290
290
// Fast path for ascii
291
291
if from_utf8_len == 1 && to_utf8_len == 1 {
292
- return replace_ascii ( & self . as_bytes ( ) , from_as_utf8[ 0 ] , to. as_bytes ( ) [ 0 ] ) ;
292
+ return unsafe {
293
+ replace_ascii ( & self . as_bytes ( ) , from_as_utf8[ 0 ] , to. as_bytes ( ) [ 0 ] )
294
+ } ;
293
295
}
294
296
capacity = get_minimum_result_capacity ( self . bytes ( ) . len ( ) , from_utf8_len, to_utf8_len) ;
295
297
}
@@ -690,7 +692,7 @@ fn convert_while_ascii(b: &[u8], convert: fn(&u8) -> u8) -> Vec<u8> {
690
692
#[ inline]
691
693
#[ cfg( not( test) ) ]
692
694
#[ cfg( not( no_global_oom_handling) ) ]
693
- fn replace_ascii ( utf8_bytes : & [ u8 ] , from : u8 , to : u8 ) -> String {
695
+ unsafe fn replace_ascii ( utf8_bytes : & [ u8 ] , from : u8 , to : u8 ) -> String {
694
696
let result: Vec < u8 > = utf8_bytes. iter ( ) . map ( |b| if * b == from { to } else { * b } ) . collect ( ) ;
695
697
// SAFETY: We replaced ascii with ascii on valid utf8 strings.
696
698
unsafe { String :: from_utf8_unchecked ( result) }
You can’t perform that action at this time.
0 commit comments