diff --git a/crates/oxc_parser/src/lexer/simd.rs b/crates/oxc_parser/src/lexer/simd.rs index 41b607a77..c0a46729c 100644 --- a/crates/oxc_parser/src/lexer/simd.rs +++ b/crates/oxc_parser/src/lexer/simd.rs @@ -39,23 +39,24 @@ impl SkipWhitespace { } pub fn simd(&mut self, bytes: &[u8]) -> &Self { - let (chunks, remainder) = bytes.as_chunks::(); + let chunks = bytes.chunks(ELEMENTS); for chunk in chunks { - self.check_chunk(chunk); - if self.found { - return self; + if chunk.len() == ELEMENTS { + self.check_chunk(chunk); + if self.found { + return self; + } + } else { + let remainder = chunk; + // Align the last chunk for avoiding the use of a scalar version + let mut chunk = [0; ELEMENTS]; + let len = remainder.len(); + chunk[..len].copy_from_slice(remainder); + self.check_chunk(&chunk); } } - if !remainder.is_empty() { - // Align the last chunk for avoiding the use of a scalar version - let mut chunk = [0; ELEMENTS]; - let len = remainder.len(); - chunk[..len].copy_from_slice(remainder); - self.check_chunk(&chunk); - } - self } @@ -120,23 +121,22 @@ impl<'a> SkipMultilineComment<'a> { } pub fn simd(&mut self) -> &Self { - let (chunks, remainder) = self.remaining.as_chunks::(); - - for chunk in chunks { - self.check(chunk, chunk.len()); - if self.found { - return self; + for chunk in self.remaining.chunks(ELEMENTS) { + if chunk.len() == ELEMENTS { + self.check(chunk, chunk.len()); + if self.found { + return self; + } + } else { + let remainder = chunk; + // Align the last chunk for avoiding the use of a scalar version + let mut chunk = [0; ELEMENTS]; + let len = remainder.len(); + chunk[..len].copy_from_slice(remainder); + self.check(&chunk, len); } } - if !remainder.is_empty() { - // Align the last chunk for avoiding the use of a scalar version - let mut chunk = [0; ELEMENTS]; - let len = remainder.len(); - chunk[..len].copy_from_slice(remainder); - self.check(&chunk, len); - } - self } diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs index 6bbadd71c..f0b28bf39 100644 --- a/crates/oxc_parser/src/lib.rs +++ b/crates/oxc_parser/src/lib.rs @@ -62,7 +62,6 @@ #![allow(clippy::wildcard_imports)] // allow for use `oxc_ast::ast::*` #![cfg_attr(not(target_arch = "wasm32"), feature(portable_simd))] -#![feature(slice_as_chunks)] mod context; mod cursor;