Skip to content

Commit

Permalink
refactor(parser): convert Lexer::read_left_angle to a single match (#…
Browse files Browse the repository at this point in the history
…4573)

`Lexer::read_left_angle` was a series of disparate `next_ascii_byte_eq` and `peek_byte` calls. Convert it to a single match on `peek_byte`. This I think will remove a couple of bounds checks.
  • Loading branch information
overlookmotel committed Jul 31, 2024
1 parent 25679e6 commit ef5418a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions crates/oxc_parser/src/lexer/punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ impl<'a> Lexer<'a> {

/// returns None for `SingleLineHTMLOpenComment` `<!--` in script mode
pub(super) fn read_left_angle(&mut self) -> Option<Kind> {
if self.next_ascii_byte_eq(b'<') {
if self.next_ascii_byte_eq(b'=') {
Some(Kind::ShiftLeftEq)
} else {
Some(Kind::ShiftLeft)
match self.peek_byte() {
Some(b'<') => {
self.consume_char();
if self.next_ascii_byte_eq(b'=') {
Some(Kind::ShiftLeftEq)
} else {
Some(Kind::ShiftLeft)
}
}
} else if self.next_ascii_byte_eq(b'=') {
Some(Kind::LtEq)
} else if self.peek_byte() == Some(b'!')
// SingleLineHTMLOpenComment `<!--` in script mode
&& self.source_type.is_script()
&& self.remaining().starts_with("!--")
{
None
} else {
Some(Kind::LAngle)
Some(b'=') => {
self.consume_char();
Some(Kind::LtEq)
}
Some(b'!') if self.source_type.is_script() && self.remaining().starts_with("!--") => {
None
}
_ => Some(Kind::LAngle),
}
}

Expand Down

0 comments on commit ef5418a

Please sign in to comment.