Skip to content

Commit b321829

Browse files
committed
Use 'equal_range' instead of full scan for rule exceptions
The original author was @WGH-, this change was proposed at #2370
1 parent 5226c42 commit b321829

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/rule_with_actions.cc

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,9 @@ void RuleWithActions::executeActionsAfterFullMatch(Transaction *trans) const {
235235
* FIXME: SecRuleUpdateActionBy should be runtime
236236
*
237237
*/
238-
for (auto &b :
239-
trans->m_rules->m_exceptions.m_action_pos_update_target_by_id) {
240-
if (m_ruleId != b.first) {
241-
continue;
242-
}
243-
ActionWithExecution *a = dynamic_cast<ActionWithExecution*>(b.second.get());
238+
auto range = trans->m_rules->m_exceptions.m_action_pos_update_target_by_id.equal_range(m_ruleId);
239+
for (auto it = range.first; it != range.second; ++it) {
240+
ActionWithExecution *a = dynamic_cast<ActionWithExecution*>(it->second.get());
244241
if (dynamic_cast<ActionDisruptive *>(a)) {
245242
trans->messageGetLast()->setRule(this);
246243
}
@@ -327,23 +324,16 @@ void RuleWithActions::executeTransformations(
327324

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

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

0 commit comments

Comments
 (0)