Skip to content

Commit

Permalink
Merge pull request #328 from dtolnay/formatpushstring
Browse files Browse the repository at this point in the history
Eliminate an allocation from Literal::byte_string
  • Loading branch information
dtolnay committed May 6, 2022
2 parents 4a3502c + d307f56 commit 4445659
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fallback.rs
Expand Up @@ -4,7 +4,7 @@ use crate::{Delimiter, Spacing, TokenTree};
use std::cell::RefCell;
#[cfg(span_locations)]
use std::cmp;
use std::fmt::{self, Debug, Display};
use std::fmt::{self, Debug, Display, Write};
use std::iter::FromIterator;
use std::mem;
use std::ops::RangeBounds;
Expand Down Expand Up @@ -876,7 +876,9 @@ impl Literal {
b'"' => escaped.push_str("\\\""),
b'\\' => escaped.push_str("\\\\"),
b'\x20'..=b'\x7E' => escaped.push(*b as char),
_ => escaped.push_str(&format!("\\x{:02X}", b)),
_ => {
let _ = write!(escaped, "\\x{:02X}", b);
}
}
}
escaped.push('"');
Expand Down

0 comments on commit 4445659

Please sign in to comment.