Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cursor offset for lexer checkpoint #11734

Merged
merged 1 commit into from
Jun 4, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

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

@dhruvmanila dhruvmanila added the internal An internal refactor or improvement label Jun 4, 2024
Comment on lines +1373 to +1376
let mut cursor = Cursor::new(self.source);
// We preserve the previous char using this method.
cursor.skip_bytes(cursor_offset.to_usize());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use Cursor::new(self.source[cursor_offset.to_usize()..] but that would always set the previous character to EOF.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dhruvmanila dhruvmanila merged commit 3b19df0 into main Jun 4, 2024
19 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/cursor-offset branch June 4, 2024 08:43
Copy link
Contributor

github-actions bot commented Jun 4, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

carljm added a commit that referenced this pull request Jun 4, 2024
* main:
  CI: add job to run tests under minimum supported rust version (msrv) (#11737)
  Lexer should consider BOM for the start offset (#11732)
  Use cursor offset for lexer checkpoint (#11734)
  red-knot: Change `resolve_global_symbol` to take `Module` as an argument (#11723)
  red-knot: Use `parse_unchecked` to get all parse errors (#11725)
  Respect per-file ignores for blanket and redirected noqa rules (#11728)
  [`pygrep_hooks`] Check blanket ignores via file-level pragmas (`PGH004`) (#11540)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants