Skip to content

Commit 0f1d3bf

Browse files
zimmerleFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Use 'equal_range' instead of full scan for rule exceptions
The original author was @WGH-, this change was proposed at #2370
1 parent 904fd03 commit 0f1d3bf

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/rule_with_actions.cc

+8-18
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,9 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans) const {
223223
* FIXME: SecRuleUpdateActionBy should be runtime
224224
*
225225
*/
226-
for (auto &b :
227-
trans->m_rules->m_exceptions.m_action_pos_update_target_by_id) {
228-
if (m_ruleId != b.first) {
229-
continue;
230-
}
231-
ActionWithExecution *a = dynamic_cast<ActionWithExecution*>(b.second.get());
226+
auto range = trans->m_rules->m_exceptions.m_action_pos_update_target_by_id.equal_range(m_ruleId);
227+
for (auto it = range.first; it != range.second; ++it) {
228+
ActionWithExecution *a = dynamic_cast<ActionWithExecution*>(it->second.get());
232229
if (dynamic_cast<ActionDisruptive *>(a)) {
233230
trans->messageGetLast()->setRule(this);
234231
}
@@ -328,23 +325,16 @@ void RuleWithActions::executeTransformations(
328325

329326
// FIXME: It can't be something different from transformation. Sort this
330327
// on rules compile time.
331-
for (auto &b :
332-
trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id) {
333-
if (m_ruleId != b.first) {
334-
continue;
335-
}
336-
Transformation *t = b.second.get();
328+
auto range = trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id.equal_range(m_ruleId);
329+
for (auto it = range.first; it != range.second; ++it) {
330+
Transformation *t = it->second.get();
337331
if (dynamic_cast<actions::transformations::None *>(t)) {
338332
none++;
339333
}
340334
}
341335

342-
for (auto &b :
343-
trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id) {
344-
if (m_ruleId != b.first) {
345-
continue;
346-
}
347-
Transformation *t = b.second.get();
336+
for (auto it = range.first; it != range.second; ++it) {
337+
Transformation *t = it->second.get();
348338
if (none == 0) {
349339
executeTransformation(trans, &results, t);
350340
}

0 commit comments

Comments
 (0)