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:
Dhruv Manilawala 2024-06-04 14:13:57 +05:30 committed by GitHub
parent 6ffb96171a
commit 3b19df04d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 14 deletions

View file

@ -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,
}