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(lexer): finish_next only clear kind and flags #8576

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
10 changes: 5 additions & 5 deletions crates/oxc_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ impl<'a> Lexer<'a> {
}

fn finish_next(&mut self, kind: Kind) -> Token {
self.token.kind = kind;
self.token.end = self.offset();
debug_assert!(self.token.start <= self.token.end);
let token = self.token;
let mut token = self.token;
token.kind = kind;
token.end = self.offset();
debug_assert!(token.start <= token.end);
self.trivia_builder.handle_token(token);
self.token = Token::default();
self.token.clear_kind_and_flags();
token
}

Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_parser/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ impl Token {
debug_assert!(!self.has_separator || self.kind.is_number() || self.kind == Kind::default());
self.has_separator = true;
}

#[inline]
pub fn clear_kind_and_flags(&mut self) {
self.kind = Kind::default();
self.is_on_new_line = false;
self.escaped = false;
self.has_separator = false;
}
}

#[cfg(test)]
Expand Down
Loading