You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(parser): use range checks for is_any_keyword() and is_number()
Replace multi-function calls and multiple enum variant checks with simple range checks, reducing assembly instructions in hot paths.
## Changes
**`is_any_keyword()`**:
- Before: Called 4 separate functions (`is_reserved_keyword()`, `is_contextual_keyword()`, `is_strict_mode_contextual_keyword()`, `is_future_reserved_keyword()`) checking 70+ enum variants with early returns
- After: Single range check `Await..=Yield` since all keywords are contiguous in the enum
**`is_number()`**:
- Before: Matched 11 separate enum variants
- After: Single range check `Decimal..=HexBigInt` since all numeric literals are contiguous
## Assembly Impact
Multi-function approach generated **5 instructions** with complex bitmask setup:
```asm
mov x8, #992
movk x8, #992, lsl #16
movk x8, #240, lsl #32
lsr x8, x8, x0
and w0, w8, #0x1
```
Range check generates **4 instructions** with simple arithmetic:
```asm
and w8, w0, #0xff
sub w8, w8, #5
cmp w8, #39
cset w0, lo
```
## Performance
- `is_any_keyword()` is called from `advance()` on **every single token**
- 20% fewer instructions (5 → 4)
- Simpler logic enables better branch prediction
- Eliminates complex constant loading
Added tests to verify enum layout assumptions remain valid.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
0 commit comments