1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

LibJS+LibRegex: Don't repeat regex match in regexp_exec()

LibRegex already implements this loop in a more performant way, so all
LibJS has to do here is to return things in the right shape, and not
loop over the input string.
Previously this was a quadratic operation on string length, which lead
to crazy execution times on failing regexps - now it's nice and fast :^)

Note that a Regex test has to be updated to remove the stateful flag as
it repeats matching on multiple strings.
This commit is contained in:
Ali Mohammad Pur 2022-02-04 23:56:44 +03:30 committed by Andreas Kling
parent 2b028f6faa
commit a962ee020a
3 changed files with 29 additions and 45 deletions

View file

@ -984,7 +984,9 @@ TEST_CASE(negative_lookahead)
{
{
// Negative lookahead with more than 2 forks difference between lookahead init and finish.
Regex<ECMA262> re(":(?!\\^\\)|1)", ECMAScriptFlags::Global);
auto options = ECMAScriptOptions { ECMAScriptFlags::Global };
options.reset_flag((ECMAScriptFlags)regex::AllFlags::Internal_Stateful);
Regex<ECMA262> re(":(?!\\^\\)|1)", options);
EXPECT_EQ(re.match(":^)").success, false);
EXPECT_EQ(re.match(":1").success, false);
EXPECT_EQ(re.match(":foobar").success, true);