Shrink Nonterminal
.
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.
This commit is contained in:
parent
c2afaba465
commit
d9592c2d9f
10 changed files with 18 additions and 16 deletions
|
@ -439,7 +439,7 @@ impl MetaItem {
|
|||
}
|
||||
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
|
||||
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),
|
||||
token::Nonterminal::NtPath(ref path) => path.clone(),
|
||||
token::Nonterminal::NtPath(ref path) => (**path).clone(),
|
||||
_ => return None,
|
||||
},
|
||||
_ => return None,
|
||||
|
|
|
@ -772,7 +772,9 @@ pub fn visit_interpolated<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut
|
|||
token::NtBlock(block) => vis.visit_block(block),
|
||||
token::NtStmt(stmt) => visit_clobber(stmt, |stmt| {
|
||||
// See reasoning above.
|
||||
vis.flat_map_stmt(stmt).expect_one("expected visitor to produce exactly one item")
|
||||
stmt.map(|stmt| {
|
||||
vis.flat_map_stmt(stmt).expect_one("expected visitor to produce exactly one item")
|
||||
})
|
||||
}),
|
||||
token::NtPat(pat) => vis.visit_pat(pat),
|
||||
token::NtExpr(expr) => vis.visit_expr(expr),
|
||||
|
|
|
@ -668,7 +668,7 @@ impl PartialEq<TokenKind> for Token {
|
|||
pub enum Nonterminal {
|
||||
NtItem(P<ast::Item>),
|
||||
NtBlock(P<ast::Block>),
|
||||
NtStmt(ast::Stmt),
|
||||
NtStmt(P<ast::Stmt>),
|
||||
NtPat(P<ast::Pat>),
|
||||
NtExpr(P<ast::Expr>),
|
||||
NtTy(P<ast::Ty>),
|
||||
|
@ -677,13 +677,13 @@ pub enum Nonterminal {
|
|||
NtLiteral(P<ast::Expr>),
|
||||
/// Stuff inside brackets for attributes
|
||||
NtMeta(P<ast::AttrItem>),
|
||||
NtPath(ast::Path),
|
||||
NtVis(ast::Visibility),
|
||||
NtPath(P<ast::Path>),
|
||||
NtVis(P<ast::Visibility>),
|
||||
}
|
||||
|
||||
// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger.
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
rustc_data_structures::static_assert_size!(Nonterminal, 48);
|
||||
rustc_data_structures::static_assert_size!(Nonterminal, 16);
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)]
|
||||
pub enum NonterminalKind {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue