about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-05-23 12:34:38 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2019-05-27 14:05:05 +1000
commit303bf1509bdf5ffd150539acf44f1c500c7079bd (patch)
tree3d9b1fe8056e3a5ec944ff786c11ed34d29ba1d4 /src/libsyntax/parse
parent21f28448e0cab81ad5697a9c01ef8dda9f730c27 (diff)
downloadrust-303bf1509bdf5ffd150539acf44f1c500c7079bd.tar.gz
rust-303bf1509bdf5ffd150539acf44f1c500c7079bd.zip
Avoid some re-interning in `to_lit_token`.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/literal.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs
index 58573093127..18019a89130 100644
--- a/src/libsyntax/parse/literal.rs
+++ b/src/libsyntax/parse/literal.rs
@@ -171,12 +171,15 @@ impl LitKind {
     /// by an AST-based macro) or unavailable (e.g. from HIR pretty-printing).
     pub fn to_lit_token(&self) -> token::Lit {
         let (kind, symbol, suffix) = match *self {
-            LitKind::Str(string, ast::StrStyle::Cooked) => {
-                let escaped = string.as_str().escape_default().to_string();
-                (token::Str, Symbol::intern(&escaped), None)
+            LitKind::Str(symbol, ast::StrStyle::Cooked) => {
+                // Don't re-intern unless the escaped string is different.
+                let s = &symbol.as_str();
+                let escaped = s.escape_default().to_string();
+                let symbol = if escaped == *s { symbol } else { Symbol::intern(&escaped) };
+                (token::Str, symbol, None)
             }
-            LitKind::Str(string, ast::StrStyle::Raw(n)) => {
-                (token::StrRaw(n), string, None)
+            LitKind::Str(symbol, ast::StrStyle::Raw(n)) => {
+                (token::StrRaw(n), symbol, None)
             }
             LitKind::ByteStr(ref bytes) => {
                 let string = bytes.iter().cloned().flat_map(ascii::escape_default)