From 55a8763d6ea606eddcf11eeaf919ca19449056fc Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:33:08 +0000 Subject: [PATCH] perf(parser): faster decoding unicode escapes in identifiers (#4579) Replace `next_char` and `peek_char` with `peek_byte` when decoding unicode escape sequences in identifiers. --- crates/oxc_parser/src/lexer/unicode.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/oxc_parser/src/lexer/unicode.rs b/crates/oxc_parser/src/lexer/unicode.rs index 1f5f598af..d67508ec7 100644 --- a/crates/oxc_parser/src/lexer/unicode.rs +++ b/crates/oxc_parser/src/lexer/unicode.rs @@ -54,14 +54,17 @@ impl<'a> Lexer<'a> { check_identifier_start: bool, ) { let start = self.offset(); - if self.next_char() != Some('u') { + if self.peek_byte() == Some(b'u') { + self.consume_char(); + } else { + self.next_char(); let range = Span::new(start, self.offset()); self.error(diagnostics::unicode_escape_sequence(range)); return; } - let value = match self.peek_char() { - Some('{') => self.unicode_code_point(), + let value = match self.peek_byte() { + Some(b'{') => self.unicode_code_point(), _ => self.surrogate_pair(), };