mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-18 18:45:07 +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
|
@ -126,7 +126,7 @@ impl<'src> TokenSource<'src> {
|
|||
}
|
||||
|
||||
/// Creates a checkpoint to which the token source can later return to using [`Self::rewind`].
|
||||
pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint<'src> {
|
||||
pub(crate) fn checkpoint(&self) -> TokenSourceCheckpoint {
|
||||
TokenSourceCheckpoint {
|
||||
lexer_checkpoint: self.lexer.checkpoint(),
|
||||
tokens_position: self.tokens.len(),
|
||||
|
@ -135,7 +135,7 @@ impl<'src> TokenSource<'src> {
|
|||
}
|
||||
|
||||
/// Restore the token source to the given checkpoint.
|
||||
pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint<'src>) {
|
||||
pub(crate) fn rewind(&mut self, checkpoint: TokenSourceCheckpoint) {
|
||||
let TokenSourceCheckpoint {
|
||||
lexer_checkpoint,
|
||||
tokens_position,
|
||||
|
@ -168,8 +168,8 @@ impl<'src> TokenSource<'src> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct TokenSourceCheckpoint<'src> {
|
||||
lexer_checkpoint: LexerCheckpoint<'src>,
|
||||
pub(crate) struct TokenSourceCheckpoint {
|
||||
lexer_checkpoint: LexerCheckpoint,
|
||||
tokens_position: usize,
|
||||
comments_position: usize,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue