Closed Validark closed 4 years ago
Side note: If the JIT engine can't make this optimization automatically, it would be optimally efficient to flatten the ranges arrays and iterate through them in pairs:
if (largeIdStartPatternSymbols.has(cp)) {
return true
}
for (
let i = 1, { length } = largeIdStartPatternRanges!;
i < length;
i += 2
) {
if (
largeIdStartPatternRanges![i - 1] <= cp &&
cp <= largeIdStartPatternRanges![i]
) {
return true
}
}
return false
Thank you for taking this improvement. LGTM.
I think it is better to not rely on any RegExp library, especially for something as simple as detecting whether a string is in a given set of strings, or whether a given number is within a given set of numbers. Thus, I converted this library to use
Set.has
instead ofRegExp.test
.(I would think Sets would be more efficient anyway, although it doesn't look like this library prioritizes efficiency in all places)
I am porting this library to Lua and this is one of the changes I had to make. I thought I might as well make it available for this version as well, if others could stand to benefit.