mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-23 19:00:59 +00:00
LibRegex: Only search start of line if pattern begins with ^
This commit is contained in:
parent
f0dd0c5107
commit
de588a97c0
Notes:
github-actions[bot]
2024-09-30 10:29:20 +00:00
Author: https://github.com/Gingeh
Commit: de588a97c0
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1570
Reviewed-by: https://github.com/alimpfard
4 changed files with 33 additions and 1 deletions
|
@ -998,6 +998,15 @@ BENCHMARK_CASE(fork_performance)
|
|||
EXPECT_EQ(result.success, true);
|
||||
}
|
||||
|
||||
BENCHMARK_CASE(anchor_performance)
|
||||
{
|
||||
Regex<ECMA262> re("^b");
|
||||
for (auto i = 0; i < 100'000; i++) {
|
||||
auto result = re.match(g_lots_of_a_s);
|
||||
EXPECT_EQ(result.success, false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(optimizer_atomic_groups)
|
||||
{
|
||||
Array tests {
|
||||
|
@ -1078,6 +1087,21 @@ TEST_CASE(optimizer_alternation)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE(start_anchor)
|
||||
{
|
||||
// Ensure that a circumflex at the start only matches the start of the line.
|
||||
{
|
||||
Regex<PosixBasic> re("^abc");
|
||||
EXPECT_EQ(re.match("123abcdef"sv, PosixFlags::Global).success, false);
|
||||
EXPECT_EQ(re.match("abc123"sv, PosixFlags::Global).success, true);
|
||||
EXPECT_EQ(re.match("123^abcdef"sv, PosixFlags::Global).success, false);
|
||||
EXPECT_EQ(re.match("^abc123"sv, PosixFlags::Global).success, false);
|
||||
|
||||
// Multiple lines
|
||||
EXPECT_EQ(re.match("123\nabc"sv, PosixFlags::Multiline).success, true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(posix_basic_dollar_is_end_anchor)
|
||||
{
|
||||
// Ensure that a dollar sign at the end only matches the end of the line.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue