Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor optimizations/v1 #12398

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/util-prefilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,24 @@ int PrefilterAddSidsResize(PrefilterRuleStore *pmq, uint32_t new_size);
static inline void PrefilterAddSids(
PrefilterRuleStore *pmq, const SigIntId *sids, uint32_t sids_size)
{
if (sids_size == 0)
return;

uint32_t new_size = pmq->rule_id_array_cnt + sids_size;
if (new_size > pmq->rule_id_array_size) {
if (PrefilterAddSidsResize(pmq, new_size) == 0) {
// Failed to allocate larger memory for all the SIDS, but
// keep as many as we can.
sids_size = pmq->rule_id_array_size - pmq->rule_id_array_cnt;
if (sids_size > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not following why is an extra indentation preferable over return if base condition doesn't match.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic I think is that it assumes the first branch (so sids_size == 0 leading to return) to be the most likely.

uint32_t new_size = pmq->rule_id_array_cnt + sids_size;
if (new_size > pmq->rule_id_array_size) {
if (PrefilterAddSidsResize(pmq, new_size) == 0) {
// Failed to allocate larger memory for all the SIDS, but
// keep as many as we can.
sids_size = pmq->rule_id_array_size - pmq->rule_id_array_cnt;
}
}
SCLogDebug("Adding %u sids", sids_size);
// Add SIDs for this pattern to the end of the array
SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt;
SigIntId *end = ptr + sids_size;
do {
*ptr++ = *sids++;
} while (ptr != end);
pmq->rule_id_array_cnt += sids_size;
}
SCLogDebug("Adding %u sids", sids_size);
// Add SIDs for this pattern to the end of the array
SigIntId *ptr = pmq->rule_id_array + pmq->rule_id_array_cnt;
SigIntId *end = ptr + sids_size;
do {
*ptr++ = *sids++;
} while (ptr != end);
pmq->rule_id_array_cnt += sids_size;
}

int PmqSetup(PrefilterRuleStore *);
Expand Down