1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibRegex+LibJS: Avoid searching for more than one match in JS RegExps

All of JS's regular expression APIs only want a single match, so avoid
trying to produce more (which will be discarded anyway).
This commit is contained in:
Ali Mohammad Pur 2022-02-04 19:29:26 +03:30 committed by Andreas Kling
parent 4c506f91fe
commit 2b028f6faa
5 changed files with 28 additions and 5 deletions

View file

@ -183,6 +183,8 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
if (input.regex_options.has_flag_set(AllFlags::Internal_Stateful))
continue_search = false;
auto single_match_only = input.regex_options.has_flag_set(AllFlags::SingleMatch);
for (auto const& view : views) {
if (lines_to_skip != 0) {
++input.line;
@ -276,6 +278,8 @@ RegexResult Matcher<Parser>::match(Vector<RegexStringView> const& views, Optiona
bool has_zero_length = state.string_position == view_index;
view_index = state.string_position - (has_zero_length ? 0 : 1);
if (single_match_only)
break;
continue;
}
if (input.regex_options.has_flag_set(AllFlags::Internal_Stateful)) {