refactor(lexer): avoid copying of self in SIMD functions (#104)

This commit is contained in:
Yoni Feng 2023-03-04 07:46:55 +02:00 committed by GitHub
parent 91c01633d6
commit dcfdce5bb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -483,7 +483,8 @@ impl<'a> Lexer<'a> {
}
let remaining = self.remaining().as_bytes();
let state = SkipWhitespace::new(self.current.token.is_on_new_line).simd(remaining);
let mut state = SkipWhitespace::new(self.current.token.is_on_new_line);
state.simd(remaining);
// SAFETY: offset is computed to the boundary
self.current.chars =
@ -512,7 +513,8 @@ impl<'a> Lexer<'a> {
fn skip_multi_line_comment(&mut self) -> Kind {
let remaining = self.remaining().as_bytes();
let newline = self.current.token.is_on_new_line;
let state = SkipMultilineComment::new(newline, remaining).simd();
let mut state = SkipMultilineComment::new(newline, remaining);
state.simd();
// SAFETY: offset is computed to the boundary
self.current.chars =

View file

@ -38,7 +38,7 @@ impl SkipWhitespace {
}
}
pub fn simd(mut self, bytes: &[u8]) -> Self {
pub fn simd(&mut self, bytes: &[u8]) -> &Self {
let (chunks, remainder) = bytes.as_chunks::<ELEMENTS>();
for chunk in chunks {
@ -119,7 +119,7 @@ impl<'a> SkipMultilineComment<'a> {
}
}
pub fn simd(mut self) -> Self {
pub fn simd(&mut self) -> &Self {
let (chunks, remainder) = self.remaining.as_chunks::<ELEMENTS>();
for chunk in chunks {