Skip to content

Commit ed9ba9b

Browse files
committed
Use P for NtMeta.
This commit reduces the size of `Nonterminal` from a 72 bytes to 40 bytes (on x86-64).
1 parent b6c9e85 commit ed9ba9b

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/librustc_parse/parser/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> Parser<'a> {
170170
pub fn parse_attr_item(&mut self) -> PResult<'a, ast::AttrItem> {
171171
let item = match self.token.kind {
172172
token::Interpolated(ref nt) => match **nt {
173-
Nonterminal::NtMeta(ref item) => Some(item.clone()),
173+
Nonterminal::NtMeta(ref item) => Some(item.clone().into_inner()),
174174
_ => None,
175175
},
176176
_ => None,

src/libsyntax/mut_visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ pub fn noop_visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis:
701701
token::NtIdent(ident, _is_raw) => vis.visit_ident(ident),
702702
token::NtLifetime(ident) => vis.visit_ident(ident),
703703
token::NtLiteral(expr) => vis.visit_expr(expr),
704-
token::NtMeta(AttrItem { path, args }) => {
704+
token::NtMeta(item) => {
705+
let AttrItem { path, args } = item.deref_mut();
705706
vis.visit_path(path);
706707
visit_mac_args(args, vis);
707708
}

src/libsyntax/token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub enum Nonterminal {
678678
NtLifetime(ast::Ident),
679679
NtLiteral(P<ast::Expr>),
680680
/// Stuff inside brackets for attributes
681-
NtMeta(ast::AttrItem),
681+
NtMeta(P<ast::AttrItem>),
682682
NtPath(ast::Path),
683683
NtVis(ast::Visibility),
684684
NtTT(TokenTree),
@@ -692,7 +692,7 @@ pub enum Nonterminal {
692692

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

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

src/libsyntax_expand/mbe/macro_parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ use rustc_parse::Directory;
8080
use rustc_parse::parser::{Parser, PathStyle, FollowedByType};
8181
use syntax::ast::{Ident, Name};
8282
use syntax::print::pprust;
83+
use syntax::ptr::P;
8384
use syntax::sess::ParseSess;
8485
use syntax::symbol::{kw, sym, Symbol};
8586
use syntax::token::{self, DocComment, Nonterminal, Token};
@@ -923,7 +924,7 @@ fn parse_nt_inner<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> PResult<'a,
923924
return Err(p.fatal(&format!("expected ident, found {}", &token_str)));
924925
}
925926
sym::path => token::NtPath(p.parse_path(PathStyle::Type)?),
926-
sym::meta => token::NtMeta(p.parse_attr_item()?),
927+
sym::meta => token::NtMeta(P(p.parse_attr_item()?)),
927928
sym::vis => token::NtVis(p.parse_visibility(FollowedByType::Yes)?),
928929
sym::lifetime => if p.check_lifetime() {
929930
token::NtLifetime(p.expect_lifetime().ident)

0 commit comments

Comments
 (0)