Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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