diff --git a/core/parser/src/lexer/identifier.rs b/core/parser/src/lexer/identifier.rs index 114fac547bc..6b1e6468031 100644 --- a/core/parser/src/lexer/identifier.rs +++ b/core/parser/src/lexer/identifier.rs @@ -35,7 +35,13 @@ impl Identifier { /// [spec]: https://tc39.es/ecma262/#sec-names-and-keywords pub(super) fn is_identifier_start(ch: u32) -> bool { const ID_START: CodePointSetDataBorrowed<'static> = CodePointSetData::new::(); - matches!(ch, 0x0024 /* $ */ | 0x005F /* _ */) || ID_START.contains32(ch) + if ch < 0x80 { + // ASCII fast path: `ID_Start` in ASCII is exactly `A-Z` and `a-z`. + #[allow(clippy::cast_possible_truncation)] + let b = ch as u8; + return b.is_ascii_alphabetic() || b == b'$' || b == b'_'; + } + ID_START.contains32(ch) } /// Checks if a character is `IdentifierPart` as per ECMAScript standards. @@ -47,10 +53,13 @@ impl Identifier { fn is_identifier_part(ch: u32) -> bool { const ID_CONTINUE: CodePointSetDataBorrowed<'static> = CodePointSetData::new::(); - matches!( - ch, - 0x0024 /* $ */ | 0x005F /* _ */ | 0x200C /* */ | 0x200D /* */ - ) || ID_CONTINUE.contains32(ch) + if ch < 0x80 { + // ASCII fast path: `ID_Continue` in ASCII is exactly `0-9`, `A-Z`, `a-z` and `_`. + #[allow(clippy::cast_possible_truncation)] + let b = ch as u8; + return b.is_ascii_alphanumeric() || b == b'$' || b == b'_'; + } + matches!(ch, 0x200C /* */ | 0x200D /* */) || ID_CONTINUE.contains32(ch) } }