Skip to content

Commit 6973e37

Browse files
committed
Add a fast-path to Debug ASCII &str
Instead of going through the `EscapeDebug` machinery, we can just skip over ASCII chars that don’t need any escaping.
1 parent e7eba09 commit 6973e37

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: core/src/fmt/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,11 @@ impl Debug for str {
24012401
f.write_char('"')?;
24022402
let mut from = 0;
24032403
for (i, c) in self.char_indices() {
2404+
// a fast path for ASCII chars that do not need escapes:
2405+
if matches!(c, ' '..='~') && !matches!(c, '\\' | '\"') {
2406+
continue;
2407+
}
2408+
24042409
let esc = c.escape_debug_ext(EscapeDebugExtArgs {
24052410
escape_grapheme_extended: true,
24062411
escape_single_quote: false,

0 commit comments

Comments
 (0)