Skip to content

Commit 00bdfc0

Browse files
committed
perf(parser): remove a bound check in match_keyword (#12778)
This is on a really cold path, so no expected performance improvement.
1 parent 09ae2a9 commit 00bdfc0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/oxc_parser/src/lexer/kind.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ impl Kind {
418418
matches!(self, LCurly | LBrack | PrivateIdentifier) || self.is_binding_identifier()
419419
}
420420

421+
#[cold]
421422
pub fn match_keyword(s: &str) -> Self {
422423
let len = s.len();
423-
if len <= 1 || len >= 12 || !s.as_bytes()[0].is_ascii_lowercase() {
424+
// SAFETY: Already checked `len <= 1`.
425+
if len <= 1 || len >= 12 || !unsafe { s.as_bytes().get_unchecked(0) }.is_ascii_lowercase() {
424426
return Ident;
425427
}
426428
Self::match_keyword_impl(s)

0 commit comments

Comments
 (0)