@@ -2407,8 +2407,8 @@ impl Debug for str {
2407
2407
b > 0x7E || b < 0x20 || b == b'\\' || b == b'"'
2408
2408
}
2409
2409
2410
- // the outer loop here splits the string into chunks of printable ASCII, which is just skipped over,
2411
- // and chunks of other chars (unicode, or ASCII that needs escaping), which is handler per-`char`.
2410
+ // the loop here first skips over runs of printable ASCII as a fast path.
2411
+ // other chars (unicode, or ASCII that needs escaping) are then handled per-`char`.
2412
2412
let mut rest = self ;
2413
2413
while rest. len ( ) > 0 {
2414
2414
let Some ( non_printable_start) = rest. as_bytes ( ) . iter ( ) . position ( |& b| needs_escape ( b) )
@@ -2421,12 +2421,8 @@ impl Debug for str {
2421
2421
// SAFETY: the position was derived from an iterator, so is known to be within bounds, and at a char boundary
2422
2422
rest = unsafe { rest. get_unchecked ( non_printable_start..) } ;
2423
2423
2424
- let printable_start =
2425
- rest. as_bytes ( ) . iter ( ) . position ( |& b| !needs_escape ( b) ) . unwrap_or ( rest. len ( ) ) ;
2426
- let prefix;
2427
- ( prefix, rest) = rest. split_at ( printable_start) ;
2428
-
2429
- for c in prefix. chars ( ) {
2424
+ let mut chars = rest. chars ( ) ;
2425
+ if let Some ( c) = chars. next ( ) {
2430
2426
let esc = c. escape_debug_ext ( EscapeDebugExtArgs {
2431
2427
escape_grapheme_extended : true ,
2432
2428
escape_single_quote : false ,
@@ -2439,6 +2435,7 @@ impl Debug for str {
2439
2435
}
2440
2436
printable_range. end += c. len_utf8 ( ) ;
2441
2437
}
2438
+ rest = chars. as_str ( ) ;
2442
2439
}
2443
2440
2444
2441
f. write_str ( & self [ printable_range] ) ?;
0 commit comments