perf(parser): speed up lexing non-decimal numbers (#4571)

Inline `Lexer::read_non_decimal` to reduce branching.
This commit is contained in:
overlookmotel 2024-07-31 00:29:00 +00:00
parent 9e5be78af5
commit bb33bcce35
2 changed files with 5 additions and 0 deletions

View file

@ -206,6 +206,7 @@ impl Kind {
)
}
#[inline] // Inline into `read_non_decimal` - see comment there as to why
pub fn matches_number_byte(self, b: u8) -> bool {
match self {
Decimal => b.is_ascii_digit(),

View file

@ -39,6 +39,10 @@ impl<'a> Lexer<'a> {
self.check_after_numeric_literal(kind)
}
// Inline into the 3 calls from `read_zero` so that value of `kind` is known
// and `kind.matches_number_byte` can be statically reduced to just the match arm
// that applies for this specific kind. `matches_number_byte` is also marked `#[inline]`.
#[inline]
fn read_non_decimal(&mut self, kind: Kind) -> Kind {
self.consume_char();