Update prism code to not do all matching recursively #197
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.
Most browsers have a limit to the number of recursive function calls that can exist in the stack. That can lead to problems when processing very large code blocks. This is also true when using global regex patterns.
See https://bugs.chromium.org/p/v8/issues/detail?id=3878 for more information about that.
This change updates most of the regex matching to no longer be recursive.
Previously inside of the
_processPattern
function it would call itself recursively until all the regex matches were complete. This works pretty well for small blocks of code, but does not work at all for large blocks of code.Regexp.exec
with global regex patterns also has to keep track of its own internal state and what it is matching against.This change updates it to work like this:
This is basically simulating a global regex without using a global regex and it allows Rainbow to process much larger blocks of code than previously. It also seems to make all highlighting a lot faster, but I have not benchmarked it.
Fixes #123
Fixes #57