Repository navigation
perf(tokenizer): classify char once per token and use ident-start table bit - #302
Merged
Merged
Conversation
…le bit Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/css-parser | 46.1 kB | 46.1 kB | +8 B |
commit: |
…pendent oracle Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
Author
|
before: |
Member
Author
|
after |
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.
Summary
CHAR_IDENT_STARTbit (ASCII letters and_) tochar_types;is_ident_startis now a single table lookup, which benefits all of its callers. The now-unusedis_alphais removed.next_token_fastreadschar_typesonce per token intoch_typeand reuses it for the whitespace, ident-start and digit checks instead of looking the character up again.No behaviour change intended. The hyphen/dot/plus lookahead blocks and the
consume_*functions are untouched.Tests proving nothing broke
New tests in
src/tokenize.test.ts→describe('first-character classification'):is_ident_start matches letters, underscore and non-ASCII for every code unit: checks all 65,536 code units against an independent oracle.a lone character becomes IDENT, WHITESPACE or NUMBER exactly when the oracle says so: tokenizes every ASCII/Latin-1 code unit plus a spread of BMP and surrogate code units and checks the token type and span against the oracle.skip_whitespace=true lands on the same token as an explicit whitespace token,identifiers may start with underscore, a letter or a non-ASCII character,digits start numbers and are not identifiers.Verification:
mainbehaviour) and on this branch, so they pin existing behaviour rather than the new implementation._fromCHAR_IDENT_STARTfails 5 tests, removing thech >= 128ident case innext_token_fastfails 2, and disabling the digit branch fails 10.tsc --noEmit, lint andknipare clean.Not benchmarked yet; meant to be benchmarked independently of the other open PRs.
🤖 Generated with Claude Code