Skip to content

Commit

Permalink
Use P for NtMeta.
Browse files Browse the repository at this point in the history
This commit reduces the size of `Nonterminal` from a 72 bytes to 40 bytes (on
x86-64).
  • Loading branch information
nnethercote committed Jan 30, 2020
1 parent 0d69fe8 commit 7d2173e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/librustc_expand/mbe/macro_parser.rs
Expand Up @@ -81,6 +81,7 @@ use rustc_parse::Directory;
use rustc_span::symbol::{kw, sym, Symbol};
use syntax::ast::{Ident, Name};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::sess::ParseSess;
use syntax::token::{self, DocComment, Nonterminal, Token};
use syntax::tokenstream::TokenStream;
Expand Down Expand Up @@ -914,7 +915,7 @@ fn parse_nt_inner<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> PResult<'a,
}
}
sym::path => token::NtPath(p.parse_path(PathStyle::Type)?),
sym::meta => token::NtMeta(p.parse_attr_item()?),
sym::meta => token::NtMeta(P(p.parse_attr_item()?)),
sym::vis => token::NtVis(p.parse_visibility(FollowedByType::Yes)?),
sym::lifetime => {
if p.check_lifetime() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/attr.rs
Expand Up @@ -177,7 +177,7 @@ impl<'a> Parser<'a> {
pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
let item = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
Nonterminal::NtMeta(ref item) => Some(item.clone()),
Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()),
_ => None,
},
_ => None,
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/mut_visit.rs
Expand Up @@ -704,7 +704,8 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
token::NtIdent(ident, _is_raw) => vis.visit_ident(ident),
token::NtLifetime(ident) => vis.visit_ident(ident),
token::NtLiteral(expr) => vis.visit_expr(expr),
token::NtMeta(AttrItem { path, args }) => {
token::NtMeta(item) => {
let AttrItem { path, args } = item.deref_mut();
vis.visit_path(path);
visit_mac_args(args, vis);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/token.rs
Expand Up @@ -673,7 +673,7 @@ pub enum Nonterminal {
NtLifetime(ast::Ident),
NtLiteral(P<ast::Expr>),
/// Stuff inside brackets for attributes
NtMeta(ast::AttrItem),
NtMeta(P<ast::AttrItem>),
NtPath(ast::Path),
NtVis(ast::Visibility),
NtTT(TokenTree),
Expand All @@ -687,7 +687,7 @@ pub enum Nonterminal {

// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
rustc_data_structures::static_assert_size!(Nonterminal, 72);
rustc_data_structures::static_assert_size!(Nonterminal, 40);

impl PartialEq for Nonterminal {
fn eq(&self, rhs: &Self) -> bool {
Expand Down

0 comments on commit 7d2173e

Please sign in to comment.