perf(lexer): peak 2 bytes after ! (#8662)

`!==` 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.
This commit is contained in:
Boshen 2025-01-23 18:19:03 +08:00 committed by GitHub
parent 878ce10296
commit 3fa87ff6a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
}
}
});