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

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