Skip to content

Conversation

@Validark
Copy link
Contributor

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 of RegExp.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.

@Validark
Copy link
Contributor Author

Validark commented Jan 13, 2020

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
@mysticatea
Copy link
Owner

Thank you for taking this improvement. LGTM.

@mysticatea mysticatea merged commit 21bd514 into mysticatea:master Apr 3, 2020
ota-meshi pushed a commit to ota-meshi/regexpp that referenced this pull request Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants