Skip to content

Commit

Permalink
perf(lexer): peak 2 bytes after !
Browse files Browse the repository at this point in the history
`!==` and `!=` is very frequent.
  • Loading branch information
Boshen committed Jan 22, 2025
1 parent a730f99 commit 39e5e28
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions crates/oxc_parser/src/lexer/byte_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,28 @@ ascii_byte_handler!(LIN(lexer) {
// !
ascii_byte_handler!(EXL(lexer) {
lexer.consume_char();
if lexer.next_ascii_byte_eq(b'=') {
if lexer.next_ascii_byte_eq(b'=') {
Kind::Neq2
} else {
Kind::Neq
if let Some(next_2_bytes) = lexer.peek_2_bytes() {
match next_2_bytes[0] {
b'=' => {
if next_2_bytes[1] == b'=' {
lexer.consume_2_chars();
Kind::Neq2
} else {
lexer.consume_char();
Kind::Neq
}
}
_ => Kind::Bang
}
} else {
Kind::Bang
// At EOF, or only 1 byte left
match lexer.peek_byte() {
Some(b'=') => {
lexer.consume_char();
Kind::Neq
}
_ => Kind::Bang
}
}
});

Expand Down

0 comments on commit 39e5e28

Please sign in to comment.