Auto merge of #34652 - jseyfried:fix_expansion_perf, r=nrc
Fix expansion performance regression **syntax-[breaking-change] cc #31645** This fixes #34630 by reverting commit5bf7970of PR #33943, which landed in #34424. By removing the `Rc<_>` wrapping around `Delimited` and `SequenceRepetition` in `TokenTree`,5bf7970made cloning `TokenTree`s more expensive. While this had no measurable performance impact on the compiler's crates, it caused an order of magnitude performance regression on some macro-heavy code in the wild. I believe this is due to clones of `TokenTree`s in `macro_parser.rs` and/or `macro_rules.rs`. r? @nrc
This commit is contained in:
@@ -237,7 +237,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
|
||||
},
|
||||
});
|
||||
|
||||
let marked_tts = mark_tts(tts, mark);
|
||||
let marked_tts = mark_tts(&tts, mark);
|
||||
Some(expandfun.expand(fld.cx, call_site, &marked_tts))
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
|
||||
}
|
||||
});
|
||||
|
||||
let marked_tts = mark_tts(tts, mark);
|
||||
let marked_tts = mark_tts(&tts, mark);
|
||||
Some(expander.expand(fld.cx, call_site, ident, marked_tts))
|
||||
}
|
||||
|
||||
@@ -1130,7 +1130,7 @@ impl Folder for Marker {
|
||||
Spanned {
|
||||
node: Mac_ {
|
||||
path: self.fold_path(node.path),
|
||||
tts: self.fold_tts(node.tts),
|
||||
tts: self.fold_tts(&node.tts),
|
||||
},
|
||||
span: self.new_span(span),
|
||||
}
|
||||
@@ -1145,7 +1145,7 @@ impl Folder for Marker {
|
||||
}
|
||||
|
||||
// apply a given mark to the given token trees. Used prior to expansion of a macro.
|
||||
fn mark_tts(tts: Vec<TokenTree>, m: Mrk) -> Vec<TokenTree> {
|
||||
fn mark_tts(tts: &[TokenTree], m: Mrk) -> Vec<TokenTree> {
|
||||
noop_fold_tts(tts, &mut Marker{mark:m, expn_id: None})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user