Skip to content

Commit 1f5167a

Browse files
committed
perf(parser): inline escaped keyword check in advance() (#14408)
## Summary Manually inline the escaped keyword check directly into `advance()` instead of calling a separate `test_escaped_keyword()` function. This eliminates function call overhead on every token advance.
1 parent ec02fe8 commit 1f5167a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/oxc_parser/src/cursor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ impl<'a> ParserImpl<'a> {
8888
/// `StringValue` of `IdentifierName` normalizes any Unicode escape sequences
8989
/// in `IdentifierName` hence such escapes cannot be used to write an Identifier
9090
/// whose code point sequence is the same as a `ReservedWord`.
91-
#[inline]
92-
fn test_escaped_keyword(&mut self, kind: Kind) {
93-
if self.cur_token().escaped() && kind.is_any_keyword() {
94-
let span = self.cur_token().span();
95-
self.error(diagnostics::escaped_keyword(span));
96-
}
91+
#[cold]
92+
fn report_escaped_keyword(&mut self, span: Span) {
93+
self.error(diagnostics::escaped_keyword(span));
9794
}
9895

9996
/// Move to the next token
10097
/// Checks if the current token is escaped if it is a keyword
10198
#[inline]
10299
fn advance(&mut self, kind: Kind) {
103-
self.test_escaped_keyword(kind);
100+
// Manually inlined escaped keyword check - escaped identifiers are extremely rare
101+
if self.token.escaped() && kind.is_any_keyword() {
102+
self.report_escaped_keyword(self.token.span());
103+
}
104104
self.prev_token_end = self.token.end();
105105
self.token = self.lexer.next_token();
106106
}

0 commit comments

Comments
 (0)