mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibRegex: Don't repeat the same fork again
If some state has already been tried, skip over it as it would never lead to a match regardless. This fixes performance/memory issues in cases like /(a+)+b/.exec("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") or /(a|a?)+b/... Fixes #2622.
This commit is contained in:
parent
7ceeb85ba7
commit
cce000d57c
Notes:
github-actions[bot]
2025-01-17 09:35:15 +00:00
Author: https://github.com/alimpfard
Commit: cce000d57c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3261
3 changed files with 66 additions and 9 deletions
|
@ -1004,9 +1004,21 @@ static auto g_lots_of_a_s = ByteString::repeated('a', 10'000'000);
|
|||
|
||||
BENCHMARK_CASE(fork_performance)
|
||||
{
|
||||
Regex<ECMA262> re("(?:aa)*");
|
||||
auto result = re.match(g_lots_of_a_s);
|
||||
EXPECT_EQ(result.success, true);
|
||||
{
|
||||
Regex<ECMA262> re("(?:aa)*");
|
||||
auto result = re.match(g_lots_of_a_s);
|
||||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
{
|
||||
Regex<ECMA262> re("(a+)+b");
|
||||
auto result = re.match(g_lots_of_a_s.substring_view(0, 100));
|
||||
EXPECT_EQ(result.success, false);
|
||||
}
|
||||
{
|
||||
Regex<ECMA262> re("^(a|a?)+$");
|
||||
auto result = re.match(ByteString::formatted("{}b", g_lots_of_a_s.substring_view(0, 100)));
|
||||
EXPECT_EQ(result.success, false);
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(anchor_performance)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue