Skip to content

Commit

Permalink
Auto merge of #80830 - Aaron1011:capture-token-empty-stack, r=petroch…
Browse files Browse the repository at this point in the history
…enkov

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.
  • Loading branch information
bors committed Jan 9, 2021
2 parents d0beb70 + 7b36408 commit 6184f23
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
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 6184f23

Please sign in to comment.