This repository was archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jul 5, 2016
The implementation of cache/restore of RegExp properties has the potential to cause a number of issues. A perfect solution is not possible because it's not possible to determine the regex that was used to turn the cached input into the cached match and group matches. The current solution simply takes the lastMatch and escapes it, wrapping any match groups in parens. One problem with this approach is that when the match is very long, it will overrun the maximum length of a RegEx in JavaScript. In this commit, we add the capability to disable restore of RegExp properties entirely, via `IntlPolyfill.__disableRegExpRestore`.
Previously createRegExpRestore build a regex with the exact characters for each part of the expression (either capturing group, or segment between capturing groups). The new solution begins with this approach, and then shortens the resulting expression by replacing each segment with a match for character count only, then setting lastIndex on the resultant RegExp to ensure that the match occurs at the expected location in the input.
createRegExpRestore now returns a restore function rather than an object that must be operated on. This commit updates the usage of this function to line up with the new implementation
1c59191
to
fdaeddb
Compare
Updated to fix conflicts. There's currently a failing test in master which fails here, too. |
This is looking good @mtlewis. What about inverting the default behavior? and just exposing a method that can be called to enable compliance with spec? This will also have to be called when running test262, but I can take care of that after you change this. |
Thanks @caridy! Wouldn't disabling cache/restore by default constitute a breaking change, and therefore imply a major version bump? It seems like the pragmatic way to get these improvements out to the largest group of people is to:
|
3573a44
to
b70852b
Compare
@mtlewis thanks for the PR, this is now merged... please try it and let us know :) |
Fantastic! Glad to hear it's merged - was a pleasure contributing :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #196.
@nosilleg and I spent some time on this today, and incorporated suggestions from #196 to improve the way createRegExpRestore works. The ability to disable cache/restore of regexes is still there, but the regexes generated now use [\s\S]{n} in conjunction with lastIndex and leftContext to make the generated regexes dramatically shorter.