Skip to content

Commit be60338

Browse files
authored
perf(es/fast-lexer): Use SIMD properly for string literals (#10172)
1 parent 35194e3 commit be60338

File tree

1 file changed

+9
-12
lines changed
  • crates/swc_ecma_fast_parser/src/lexer

1 file changed

+9
-12
lines changed

crates/swc_ecma_fast_parser/src/lexer/string.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,22 @@ impl Lexer<'_> {
234234
let newline_vec = u8x16::splat(b'\n');
235235
let carriage_vec = u8x16::splat(b'\r');
236236

237-
// Check for presence of special characters
237+
// Check for presence of special characters with a single combined mask
238238
let quote_mask = chunk.cmp_eq(quote_vec);
239239
let backslash_mask = chunk.cmp_eq(backslash_vec);
240240
let newline_mask = chunk.cmp_eq(newline_vec);
241241
let carriage_mask = chunk.cmp_eq(carriage_vec);
242242

243-
// Convert masks to arrays for checking
244-
let quote_arr = quote_mask.to_array();
245-
let backslash_arr = backslash_mask.to_array();
246-
let newline_arr = newline_mask.to_array();
247-
let carriage_arr = carriage_mask.to_array();
243+
// Combine all masks with OR operation
244+
let combined_mask = quote_mask | backslash_mask | newline_mask | carriage_mask;
248245

249-
// Check for any special character that requires detailed processing
246+
// Convert combined mask to array to check if any special character was found
247+
let mask_array = combined_mask.to_array();
248+
249+
// Check if any element in the mask array is non-zero
250+
#[allow(clippy::needless_range_loop)]
250251
for i in 0..16 {
251-
if quote_arr[i] != 0
252-
|| backslash_arr[i] != 0
253-
|| newline_arr[i] != 0
254-
|| carriage_arr[i] != 0
255-
{
252+
if mask_array[i] != 0 {
256253
// We found a character that needs special handling
257254
// Process from here using the standard algorithm
258255
return self.find_string_end_standard(pos + i as u32, rest, quote);

0 commit comments

Comments
 (0)