Skip to content

Commit 191e76c

Browse files
committed
fix perf issue in macro parser
For a fuller description of the performance issue fixed by this: #51754 (comment)
1 parent 9fd3d78 commit 191e76c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,17 @@ pub fn parse(
696696
} else {
697697
return Failure(parser.span, token::Eof);
698698
}
699+
} else {
700+
// Performance hack: eof_items may share matchers via Rc with other things that we want
701+
// to modify. Dropping eof_items now may drop these refcounts to 1, preventing an
702+
// unnecessary implicit clone later in Rc::make_mut.
703+
drop(eof_items);
699704
}
705+
700706
// Another possibility is that we need to call out to parse some rust nonterminal
701707
// (black-box) parser. However, if there is not EXACTLY ONE of these, something is wrong.
702-
else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
708+
assert!(!token_name_eq(&parser.token, &token::Eof));
709+
if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
703710
let nts = bb_items
704711
.iter()
705712
.map(|item| match item.top_elts.get_tt(item.idx) {

0 commit comments

Comments
 (0)