From bba824bc3400a3fece29b6afca0e5dfbff9fc3aa Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 31 Jul 2024 03:32:57 +0000 Subject: [PATCH] refactor(parser): convert `Lexer::read_minus` to a single match (#4574) Same as #4573. Convert `Lexer::read_minus` to a single match rather than multiple `next_ascii_byte_eq` calls. --- crates/oxc_parser/src/lexer/punctuation.rs | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/oxc_parser/src/lexer/punctuation.rs b/crates/oxc_parser/src/lexer/punctuation.rs index cc392e9a2d175..d810f5fb84007 100644 --- a/crates/oxc_parser/src/lexer/punctuation.rs +++ b/crates/oxc_parser/src/lexer/punctuation.rs @@ -38,20 +38,23 @@ impl<'a> Lexer<'a> { /// returns None for `SingleLineHTMLCloseComment` `-->` in script mode pub(super) fn read_minus(&mut self) -> Option { - if self.next_ascii_byte_eq(b'-') { - // SingleLineHTMLCloseComment `-->` in script mode - if self.token.is_on_new_line - && self.source_type.is_script() - && self.next_ascii_byte_eq(b'>') - { - None - } else { - Some(Kind::Minus2) + match self.peek_byte() { + Some(b'-') => { + self.consume_char(); + if self.token.is_on_new_line + && self.source_type.is_script() + && self.next_ascii_byte_eq(b'>') + { + None + } else { + Some(Kind::Minus2) + } } - } else if self.next_ascii_byte_eq(b'=') { - Some(Kind::MinusEq) - } else { - Some(Kind::Minus) + Some(b'=') => { + self.consume_char(); + Some(Kind::MinusEq) + } + _ => Some(Kind::Minus), } }