Skip to content

Commit

Permalink
Use an empty TokenCursorFrame stack when capturing tokens
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aaron1011 committed Jan 8, 2021
1 parent 26438b4 commit 7b36408
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Expand Up @@ -1239,7 +1239,15 @@ impl<'a> Parser<'a> {
f: impl FnOnce(&mut Self) -> PResult<'a, R>,
) -> PResult<'a, (R, Option<LazyTokenStream>)> {
let start_token = (self.token.clone(), self.token_spacing);
let cursor_snapshot = self.token_cursor.clone();
let cursor_snapshot = TokenCursor {
frame: self.token_cursor.frame.clone(),
// We only ever capture tokens within our current frame,
// so we can just use an empty frame stack
stack: vec![],
desugar_doc_comments: self.token_cursor.desugar_doc_comments,
num_next_calls: self.token_cursor.num_next_calls,
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
};

let ret = f(self)?;

Expand Down

0 comments on commit 7b36408

Please sign in to comment.