mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 17:10:53 +00:00
Use cursor offset for lexer checkpoint (#11734)
## Summary This PR updates the lexer checkpoint to store the cursor offset instead of cloning the cursor itself. This reduces the size of `LexerCheckpoint` from 136 to 112 bytes and also removes the need for lifetime. ## Test Plan `cargo insta test`
This commit is contained in:
parent
6ffb96171a
commit
3b19df04d7
3 changed files with 18 additions and 14 deletions
|
@ -609,7 +609,7 @@ impl<'src> Parser<'src> {
|
|||
}
|
||||
|
||||
/// Creates a checkpoint to which the parser can later return to using [`Self::rewind`].
|
||||
fn checkpoint(&self) -> ParserCheckpoint<'src> {
|
||||
fn checkpoint(&self) -> ParserCheckpoint {
|
||||
ParserCheckpoint {
|
||||
tokens: self.tokens.checkpoint(),
|
||||
errors_position: self.errors.len(),
|
||||
|
@ -620,7 +620,7 @@ impl<'src> Parser<'src> {
|
|||
}
|
||||
|
||||
/// Restore the parser to the given checkpoint.
|
||||
fn rewind(&mut self, checkpoint: ParserCheckpoint<'src>) {
|
||||
fn rewind(&mut self, checkpoint: ParserCheckpoint) {
|
||||
let ParserCheckpoint {
|
||||
tokens,
|
||||
errors_position,
|
||||
|
@ -637,8 +637,8 @@ impl<'src> Parser<'src> {
|
|||
}
|
||||
}
|
||||
|
||||
struct ParserCheckpoint<'src> {
|
||||
tokens: TokenSourceCheckpoint<'src>,
|
||||
struct ParserCheckpoint {
|
||||
tokens: TokenSourceCheckpoint,
|
||||
errors_position: usize,
|
||||
current_token_id: TokenId,
|
||||
prev_token_end: TextSize,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue