Skip to content

Commit

Permalink
perf(parser): speed up lexing non-decimal numbers (#4571)
Browse files Browse the repository at this point in the history
Inline `Lexer::read_non_decimal` to reduce branching.
  • Loading branch information
overlookmotel committed Jul 31, 2024
1 parent 9e5be78 commit bb33bcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/oxc_parser/src/lexer/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_parser/src/lexer/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit bb33bcc

Please sign in to comment.