From 1742b58ab152ce71e76c8da72a1f135e3db535c6 Mon Sep 17 00:00:00 2001 From: g4lb Date: Sat, 21 Nov 2026 11:49:03 +0200 Subject: [PATCH 1/2] perf(parser): check ASCII identifier characters without the ICU lookup --- core/parser/src/lexer/identifier.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/parser/src/lexer/identifier.rs b/core/parser/src/lexer/identifier.rs index 114fac547bc..a84dc8d4e93 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,6 +53,12 @@ impl Identifier { fn is_identifier_part(ch: u32) -> bool { const ID_CONTINUE: CodePointSetDataBorrowed<'static> = CodePointSetData::new::(); + 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, 0x0024 /* $ */ | 0x005F /* _ */ | 0x200C /* */ | 0x200D /* */ From 10c2bd90064db2b300f5f06db42bc713f12387e4 Mon Sep 17 00:00:00 2001 From: g4lb Date: Mon, 23 Nov 2026 21:27:05 +0200 Subject: [PATCH 2/2] refactor(parser): drop the unreachable `$` and `_` cases in `is_identifier_part` --- core/parser/src/lexer/identifier.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/parser/src/lexer/identifier.rs b/core/parser/src/lexer/identifier.rs index a84dc8d4e93..6b1e6468031 100644 --- a/core/parser/src/lexer/identifier.rs +++ b/core/parser/src/lexer/identifier.rs @@ -59,10 +59,7 @@ impl Identifier { let b = ch as u8; return b.is_ascii_alphanumeric() || b == b'$' || b == b'_'; } - matches!( - ch, - 0x0024 /* $ */ | 0x005F /* _ */ | 0x200C /* */ | 0x200D /* */ - ) || ID_CONTINUE.contains32(ch) + matches!(ch, 0x200C /* */ | 0x200D /* */) || ID_CONTINUE.contains32(ch) } }