Skip to content

Commit 303bf15

Browse files
committed
Avoid some re-interning in to_lit_token.
1 parent 21f2844 commit 303bf15

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/libsyntax/parse/literal.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,15 @@ impl LitKind {
171171
/// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
172172
pub fn to_lit_token(&self) -> token::Lit {
173173
let (kind, symbol, suffix) = match *self {
174-
LitKind::Str(string, ast::StrStyle::Cooked) => {
175-
let escaped = string.as_str().escape_default().to_string();
176-
(token::Str, Symbol::intern(&escaped), None)
174+
LitKind::Str(symbol, ast::StrStyle::Cooked) => {
175+
// Don't re-intern unless the escaped string is different.
176+
let s = &symbol.as_str();
177+
let escaped = s.escape_default().to_string();
178+
let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) };
179+
(token::Str, symbol, None)
177180
}
178-
LitKind::Str(string, ast::StrStyle::Raw(n)) => {
179-
(token::StrRaw(n), string, None)
181+
LitKind::Str(symbol, ast::StrStyle::Raw(n)) => {
182+
(token::StrRaw(n), symbol, None)
180183
}
181184
LitKind::ByteStr(ref bytes) => {
182185
let string = bytes.iter().cloned().flat_map(ascii::escape_default)

0 commit comments

Comments
 (0)