mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibRegex: Add a basic optimization pass
This currently tries to convert forking loops to atomic groups, and unify the left side of alternations.
This commit is contained in:
parent
913382734c
commit
246ab432ff
9 changed files with 677 additions and 24 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibTest/TestCase.h> // import first, to prevent warning of VERIFY* redefinition
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Tuple.h>
|
||||
#include <LibRegex/Regex.h>
|
||||
#include <LibRegex/RegexDebug.h>
|
||||
#include <stdio.h>
|
||||
|
@ -887,3 +888,21 @@ BENCHMARK_CASE(fork_performance)
|
|||
auto result = re.match(g_lots_of_a_s);
|
||||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
|
||||
TEST_CASE(optimizer_atomic_groups)
|
||||
{
|
||||
Array tests {
|
||||
// Fork -> ForkReplace
|
||||
Tuple { "a*b"sv, "aaaaa"sv, false },
|
||||
Tuple { "a+b"sv, "aaaaa"sv, false },
|
||||
// Alternative fuse
|
||||
Tuple { "(abcfoo|abcbar|abcbaz).*x"sv, "abcbarx"sv, true },
|
||||
Tuple { "(a|a)"sv, "a"sv, true },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.get<0>());
|
||||
auto result = re.match(test.get<1>());
|
||||
EXPECT_EQ(result.success, test.get<2>());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue