Skip to content

Commit 7b36408

Browse files
committed
Use an empty TokenCursorFrame stack when capturing tokens
We will never need to pop past our starting frame during token capturing. Using an empty stack allows us to avoid pointless heap allocations/deallocations.
1 parent 26438b4 commit 7b36408

File tree

1 file changed

+9
-1
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+9
-1
lines changed

compiler/rustc_parse/src/parser/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,15 @@ impl<'a> Parser<'a> {
12391239
f: impl FnOnce(&mut Self) -> PResult<'a, R>,
12401240
) -> PResult<'a, (R, Option<LazyTokenStream>)> {
12411241
let start_token = (self.token.clone(), self.token_spacing);
1242-
let cursor_snapshot = self.token_cursor.clone();
1242+
let cursor_snapshot = TokenCursor {
1243+
frame: self.token_cursor.frame.clone(),
1244+
// We only ever capture tokens within our current frame,
1245+
// so we can just use an empty frame stack
1246+
stack: vec![],
1247+
desugar_doc_comments: self.token_cursor.desugar_doc_comments,
1248+
num_next_calls: self.token_cursor.num_next_calls,
1249+
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
1250+
};
12431251

12441252
let ret = f(self)?;
12451253

0 commit comments

Comments
 (0)