mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-31 22:16:49 +00:00
perf: avoid stack allocation and make use of switch to select behavior on rule matching strategy
Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
This commit is contained in:
parent
1705c0dab3
commit
6acd924c50
@ -388,21 +388,28 @@ std::unique_ptr<std::vector<falco_engine::rule_result>> falco_engine::process_ev
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_rule_matching == falco_common::rule_matching::ALL)
|
||||
switch (m_rule_matching)
|
||||
{
|
||||
case falco_common::rule_matching::ALL:
|
||||
if (source->m_rules.size() > 0)
|
||||
{
|
||||
source->m_rules.clear();
|
||||
}
|
||||
if (!source->ruleset->run(ev, source->m_rules, ruleset_id))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else if (m_rule_matching == falco_common::rule_matching::FIRST)
|
||||
{
|
||||
falco_rule rule;
|
||||
if (!source->ruleset->run(ev, rule, ruleset_id))
|
||||
break;
|
||||
case falco_common::rule_matching::FIRST:
|
||||
if (source->m_rules.size() != 1)
|
||||
{
|
||||
source->m_rules.resize(1);
|
||||
}
|
||||
if (!source->ruleset->run(ev, source->m_rules[0], ruleset_id))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
source->m_rules.push_back(rule);
|
||||
break;
|
||||
}
|
||||
|
||||
auto res = std::make_unique<std::vector<falco_engine::rule_result>>();
|
||||
@ -420,10 +427,6 @@ std::unique_ptr<std::vector<falco_engine::rule_result>> falco_engine::process_ev
|
||||
res->push_back(rule_result);
|
||||
}
|
||||
|
||||
if (source->m_rules.size() > 0)
|
||||
{
|
||||
source->m_rules.clear();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ falco_configuration::falco_configuration():
|
||||
m_notifications_rate(0),
|
||||
m_notifications_max_burst(1000),
|
||||
m_watch_config_files(true),
|
||||
m_rule_matching(falco_common::rule_matching::FIRST),
|
||||
m_buffered_outputs(false),
|
||||
m_time_format_iso_8601(false),
|
||||
m_output_timeout(2000),
|
||||
|
Loading…
Reference in New Issue
Block a user