From b32182940d558db803c063575552621bc061380b Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 10 Aug 2020 09:51:02 -0300 Subject: [PATCH] Use 'equal_range' instead of full scan for rule exceptions The original author was @WGH-, this change was proposed at #2370 --- src/rule_with_actions.cc | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/rule_with_actions.cc b/src/rule_with_actions.cc index b87899ca..5a0dea7a 100644 --- a/src/rule_with_actions.cc +++ b/src/rule_with_actions.cc @@ -235,12 +235,9 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans) const { * FIXME: SecRuleUpdateActionBy should be runtime * */ - for (auto &b : - trans->m_rules->m_exceptions.m_action_pos_update_target_by_id) { - if (m_ruleId != b.first) { - continue; - } - ActionWithExecution *a = dynamic_cast(b.second.get()); + auto range = trans->m_rules->m_exceptions.m_action_pos_update_target_by_id.equal_range(m_ruleId); + for (auto it = range.first; it != range.second; ++it) { + ActionWithExecution *a = dynamic_cast(it->second.get()); if (dynamic_cast(a)) { trans->messageGetLast()->setRule(this); } @@ -327,23 +324,16 @@ void RuleWithActions::executeTransformations( // FIXME: It can't be something different from transformation. Sort this // on rules compile time. - for (auto &b : - trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id) { - if (m_ruleId != b.first) { - continue; - } - Transformation *t = b.second.get(); + auto range = trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id.equal_range(m_ruleId); + for (auto it = range.first; it != range.second; ++it) { + Transformation *t = it->second.get(); if (dynamic_cast(t)) { none++; } } - for (auto &b : - trans->m_rules->m_exceptions.m_action_transformation_update_target_by_id) { - if (m_ruleId != b.first) { - continue; - } - Transformation *t = b.second.get(); + for (auto it = range.first; it != range.second; ++it) { + Transformation *t = it->second.get(); if (none == 0) { executeTransformation(trans, &results, t); }