Fixed some cases of quadratic worst-case runtime #2922
This fixes a few of the cases I described in #2597.
Basically, the regex engine moves the regexes over the string from left to right and is typically forced to check each of the n suffixes for a string of length n. There are various optimizations employed by the regex engine that reduces the number of suffixes that have to be tested but it's usually still linear, O(n). If the regex engine then also takes O(n) steps to reject each of those suffixes, we get a worst-case runtime of O(n^2).
The fixes in this PR also have the same strategy: reject suffixes in O(1). So all rejecting suffixes will be rejected in (on average) O(1).
I have to note that this PR fixes not all of these cases, by far. I only fixed the cases that were easy to fix.
All of the changed regexes still behave the same in the context of Prism's matching algorithm.
The only exception is JS stack trace where I added an additional lookbehind group as part of the fix. Hence the changed test case.
The text was updated successfully, but these errors were encountered:
JS File Size Changes (gzipped)
A total of 71 files have changed, with a combined diff of +182 B (+0.2%).