Skip to content

Commit

Permalink
perf(lexer): peak 2 bytes after ! (#8662)
Browse files Browse the repository at this point in the history
`!==` and `!=` is very frequent.

<img width="845" alt="image"
src="https://github.com/user-attachments/assets/91ff20fc-ae1c-4fb9-9444-4eb90d8e95f3"
/>

Picked this up while profiling.
  • Loading branch information
Boshen authored Jan 23, 2025
1 parent 878ce10 commit 3fa87ff
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 @@ -209,14 +209,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 3fa87ff

Please sign in to comment.