summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-13 22:46:21 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-14 16:09:58 +0430
commit794dc368f19b1c9bf7161def8a26e1282e78a925 (patch)
treec574238bba988796183ac28a9d62fbc3fb98a7e0
parent214410b3979ceef274fc525dad628d27615edaf8 (diff)
downloadserenity-794dc368f19b1c9bf7161def8a26e1282e78a925.zip
LibRegex: Avoid prepending items to vectors
-rw-r--r--Userland/Libraries/LibRegex/RegexMatcher.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibRegex/RegexMatcher.cpp b/Userland/Libraries/LibRegex/RegexMatcher.cpp
index b402442220..a7ade1f533 100644
--- a/Userland/Libraries/LibRegex/RegexMatcher.cpp
+++ b/Userland/Libraries/LibRegex/RegexMatcher.cpp
@@ -293,7 +293,7 @@ Optional<bool> Matcher<Parser>::execute(const MatchInput& input, MatchState& sta
if (recursion_level > c_max_recursion)
return false;
- Vector<MatchState> fork_low_prio_states;
+ Vector<MatchState, 64> reversed_fork_low_prio_states;
MatchState fork_high_prio_state;
Optional<bool> success;
@@ -323,7 +323,7 @@ Optional<bool> Matcher<Parser>::execute(const MatchInput& input, MatchState& sta
switch (result) {
case ExecutionResult::Fork_PrioLow:
- fork_low_prio_states.prepend(state);
+ reversed_fork_low_prio_states.append(state);
continue;
case ExecutionResult::Fork_PrioHigh:
fork_high_prio_state = state;
@@ -344,8 +344,13 @@ Optional<bool> Matcher<Parser>::execute(const MatchInput& input, MatchState& sta
return true;
case ExecutionResult::Failed:
return false;
- case ExecutionResult::Failed_ExecuteLowPrioForks:
- return execute_low_prio_forks(input, state, output, fork_low_prio_states, recursion_level + 1);
+ case ExecutionResult::Failed_ExecuteLowPrioForks: {
+ Vector<MatchState> fork_low_prio_states;
+ fork_low_prio_states.ensure_capacity(reversed_fork_low_prio_states.size());
+ for (ssize_t i = reversed_fork_low_prio_states.size() - 1; i >= 0; i--)
+ fork_low_prio_states.unchecked_append(move(reversed_fork_low_prio_states[i]));
+ return execute_low_prio_forks(input, state, output, move(fork_low_prio_states), recursion_level + 1);
+ }
}
}