Repository navigation
fix(lexer): stop rechecking UTF-8 on every character - #965
Merged
LunaStev merged 1 commit intoOct 19, 2026
Merged
Conversation
Signed-off-by: hiyouwhatsapp <[email protected]>
hiyouwhatsapp
marked this pull request as ready for review
October 19, 2026 12:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #935
advanceandpeekwere checking all the remaining source withfrom_utf8every time they read a character. So a long comment was getting checked over and over, even though the source is already a valid&strThis just reads the next character from the string and moves forward by its byte length
Added a longer test with ASCII and multibyte comments, a nested comment, a Unicode identifier and a string. It checks the tokens and their positions with LF, CRLF and CR line endings. That test passes on the old code too, I wanted to make sure the cursor still gives the same result
I also timed the lexer before and after. A 240 KB comment went from about 4.4 seconds to 0.036 in the debug build. At 30 KB it went from 0.083 to 0.0046, and doubling the input now takes roughly twice as long. These are medians of five runs on the same machine, just timing the lexer
Testing: All 12 lexer tests pass at both O0 and O2 with Rust 1.89.0 on Windows. Built the actual
utils,errorandlexersources directly withrustc.cargo fmt --all --checkandgit diff --checkpass too but I haven't run the full workspace checks or Wave corpus, this setup doesn't have the LLVM SDK