]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/pmq: assist branch prediction
authorVictor Julien <vjulien@oisf.net>
Mon, 11 Sep 2023 07:21:28 +0000 (07:21 +0000)
committerVictor Julien <victor@inliniac.net>
Tue, 25 Feb 2025 14:49:32 +0000 (15:49 +0100)
src/util-prefilter.h

index 51a65c55b443ffb8c5a52e82fba9a4608808c9bc..125120480d9d3e64c5b4d016ee42b2d31ec174aa 100644 (file)
@@ -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) {
+        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 *);