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): cache cur_kind() to eliminate redundant calls (#14411)
## Summary
Optimization to reduce redundant token kind extraction in hot paths by caching `cur_kind()` results before compound checks.
## Problem
- Compound checks like `self.at(X) || self.at(Y)` call `cur_kind()` twice
- Pattern `self.at(close) || self.has_fatal_error()` calls `cur_kind()` twice since `has_fatal_error()` internally calls it
- Token kind extraction involves bit-packing operations: `((self.0 >> 64) & 0xFF) as u8`
## Solution
Cache `cur_kind()` in a local variable before compound checks to eliminate redundant calls.
## Changes
- **`cursor.rs:parse_delimited_list()`**: Hot loop parsing arrays, objects, parameters - reduced from 2-3 calls per iteration to 1
- **`arrow.rs:68`**: Cached kind for `LParen`/`LAngle` check
- **`module.rs:101`**: Cached kind for `LCurly`/`Star` check
- **`types.rs`**: Fixed 3 locations (lines 91, 558, 1188) with double `at()` calls
## Impact
Every JavaScript array, object literal, function parameter list, and TypeScript type now extracts the token kind fewer times during parsing.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
0 commit comments