Skip to content

Commit d253c69

Browse files
committed
Auto merge of #121150 - Swatinem:debug-ascii-str, r=<try>
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. --- This is an alternative / a companion to #121138. The other PR is adding the fast path deep within `EscapeDebug`, whereas this skips as early as possible.
2 parents bfe762e + 04602a2 commit d253c69

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/core/src/fmt/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,11 @@ impl Debug for str {
23632363
f.write_char('"')?;
23642364
let mut from = 0;
23652365
for (i, c) in self.char_indices() {
2366+
// a fast path for ASCII chars that do not need escapes:
2367+
if matches!(c, ' '..='~') && !matches!(c, '\\' | '\"') {
2368+
continue;
2369+
}
2370+
23662371
let esc = c.escape_debug_ext(EscapeDebugExtArgs {
23672372
escape_grapheme_extended: true,
23682373
escape_single_quote: false,

0 commit comments

Comments
 (0)