diff options
| author | bors <bors@rust-lang.org> | 2019-05-27 06:53:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-27 06:53:53 +0000 |
| commit | ab7cf71d4c6dd1696cb0eb52ad172bce296578cc (patch) | |
| tree | 48c001b66e3a12c491ca5e20b8fb63d303c08636 /src/libsyntax/parse | |
| parent | be10e6277b738df3cc8ac316872227879118cc64 (diff) | |
| parent | 33a3206dc5e7f267617a625d8b31ccc3250cdc1e (diff) | |
| download | rust-ab7cf71d4c6dd1696cb0eb52ad172bce296578cc.tar.gz rust-ab7cf71d4c6dd1696cb0eb52ad172bce296578cc.zip | |
Auto merge of #61035 - nnethercote:avoid-more-symbol-interning, r=petrochenkov
Avoid more symbol interning r? @petrochenkov
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/diagnostics.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/literal.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 4 |
5 files changed, 23 insertions, 20 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs index 9431b559da5..b3d49524d76 100644 --- a/src/libsyntax/parse/diagnostics.rs +++ b/src/libsyntax/parse/diagnostics.rs @@ -8,7 +8,7 @@ use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, Token use crate::print::pprust; use crate::ptr::P; use crate::source_map::Spanned; -use crate::symbol::kw; +use crate::symbol::{kw, sym}; use crate::ThinVec; use crate::util::parser::AssocOp; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; @@ -263,7 +263,7 @@ impl<'a> Parser<'a> { }; self.last_unexpected_token_span = Some(self.span); let mut err = self.fatal(&msg_exp); - if self.token.is_ident_named("and") { + if self.token.is_ident_named(sym::and) { err.span_suggestion_short( self.span, "use `&&` instead of `and` for the boolean operator", @@ -271,7 +271,7 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); } - if self.token.is_ident_named("or") { + if self.token.is_ident_named(sym::or) { err.span_suggestion_short( self.span, "use `||` instead of `or` for the boolean operator", diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index deb76d6d70a..a06a84f162a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1,7 +1,7 @@ use crate::ast::{self, Ident}; use crate::parse::ParseSess; use crate::parse::token::{self, Token}; -use crate::symbol::Symbol; +use crate::symbol::{sym, Symbol}; use crate::parse::unescape; use crate::parse::unescape_error_reporting::{emit_unescape_error, push_escaped_char}; @@ -754,7 +754,7 @@ impl<'a> StringReader<'a> { } _ => { // just a 0 - return (token::Integer, self.name_from(start_bpos)); + return (token::Integer, sym::integer(0)); } } } else if c.is_digit(10) { diff --git a/src/libsyntax/parse/literal.rs b/src/libsyntax/parse/literal.rs index 0305b1f59b9..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) @@ -193,14 +196,14 @@ impl LitKind { } LitKind::Int(n, ty) => { let suffix = match ty { - ast::LitIntType::Unsigned(ty) => Some(Symbol::intern(ty.ty_to_string())), - ast::LitIntType::Signed(ty) => Some(Symbol::intern(ty.ty_to_string())), + ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()), + ast::LitIntType::Signed(ty) => Some(ty.to_symbol()), ast::LitIntType::Unsuffixed => None, }; - (token::Integer, Symbol::intern(&n.to_string()), suffix) + (token::Integer, sym::integer(n), suffix) } LitKind::Float(symbol, ty) => { - (token::Float, symbol, Some(Symbol::intern(ty.ty_to_string()))) + (token::Float, symbol, Some(ty.to_symbol())) } LitKind::FloatUnsuffixed(symbol) => { (token::Float, symbol, None) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6c29437362c..07efeaa4cf2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2759,7 +2759,7 @@ impl<'a> Parser<'a> { let (span, e) = self.interpolated_or_expr_span(e)?; (lo.to(span), ExprKind::Box(e)) } - token::Ident(..) if self.token.is_ident_named("not") => { + token::Ident(..) if self.token.is_ident_named(sym::not) => { // `not` is just an ordinary identifier in Rust-the-language, // but as `rustc`-the-compiler, we can issue clever diagnostics // for confused users who really want to say `!` @@ -4592,7 +4592,7 @@ impl<'a> Parser<'a> { let do_not_suggest_help = self.token.is_keyword(kw::In) || self.token == token::Colon; - if self.token.is_ident_named("and") { + if self.token.is_ident_named(sym::and) { e.span_suggestion_short( self.span, "use `&&` instead of `and` for the boolean operator", @@ -4600,7 +4600,7 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); } - if self.token.is_ident_named("or") { + if self.token.is_ident_named(sym::or) { e.span_suggestion_short( self.span, "use `||` instead of `or` for the boolean operator", @@ -5787,7 +5787,7 @@ impl<'a> Parser<'a> { VisibilityKind::Inherited => {} _ => { let is_macro_rules: bool = match self.token { - token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"), + token::Ident(sid, _) => sid.name == sym::macro_rules, _ => false, }; let mut err = if is_macro_rules { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index e5361b2db4e..47185df8d61 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -391,9 +391,9 @@ impl Token { /// Returns `true` if the token is a identifier whose name is the given /// string slice. - crate fn is_ident_named(&self, name: &str) -> bool { + crate fn is_ident_named(&self, name: Symbol) -> bool { match self.ident() { - Some((ident, _)) => ident.as_str() == name, + Some((ident, _)) => ident.name == name, None => false } } |
