diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index 0589f46a88cc3..b275d657b4e97 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -83,11 +83,8 @@ impl<'a> Lexer<'a> { source = "\0"; } - let token = Token { - // the first token is at the start of file, so is allows on a new line - is_on_new_line: true, - ..Token::default() - }; + // The first token is at the start of file, so is allows on a new line + let token = Token::new_on_new_line(); let current = LexerCheckpoint { chars: source.chars(), token, errors_pos: 0 }; Self { allocator, diff --git a/crates/oxc_parser/src/lexer/token.rs b/crates/oxc_parser/src/lexer/token.rs index 5d2f576412e25..122c5080b1d2d 100644 --- a/crates/oxc_parser/src/lexer/token.rs +++ b/crates/oxc_parser/src/lexer/token.rs @@ -25,14 +25,24 @@ pub struct Token { /// [Lexer::escaped_strings]: [super::Lexer::escaped_strings] /// [Lexer::escaped_templates]: [super::Lexer::escaped_templates] pub escaped: bool, + + // Padding to fill to 16 bytes. + // This makes copying a `Token` 1 x xmmword load & store, rather than 1 x dword + 1 x qword + // and `Token::default()` is 1 x xmmword store, rather than 1 x dword + 1 x qword. + _padding1: u8, + _padding2: u32, } #[cfg(target_pointer_width = "64")] mod size_asserts { - oxc_index::assert_eq_size!(super::Token, [u8; 12]); + oxc_index::assert_eq_size!(super::Token, [u8; 16]); } impl Token { + pub(super) fn new_on_new_line() -> Self { + Self { is_on_new_line: true, ..Self::default() } + } + pub fn span(&self) -> Span { Span::new(self.start, self.end) }