Skip to content

Commit

Permalink
perf(lexer): finish_next only clear kind and flags
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel authored and Boshen committed Jan 18, 2025
1 parent 63eb298 commit a5e9929
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
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

0 comments on commit a5e9929

Please sign in to comment.