]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: optimize pstate check
authorVictor Julien <vjulien@oisf.net>
Mon, 11 Sep 2023 07:22:16 +0000 (07:22 +0000)
committerVictor Julien <victor@inliniac.net>
Tue, 25 Feb 2025 14:49:32 +0000 (15:49 +0100)
To assist branch prediction, which showed a 100% miss rate, assume pstate
is non-NULL. Code review suggests all paths leading to the function actually
check pstate first, or alstate which can only be non-NULL if pstate was first
initialized. For now add a debug check.

src/app-layer-parser.c

index 4d0dbcc48af6bcc8f74e08d303e824932175e21c..6a8f66c5a0909dacef9bf11f0155e94d12809381 100644 (file)
@@ -698,10 +698,11 @@ uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint
 {
     SCEnter();
 
-    if (pstate == NULL)
-        SCReturnCT(0ULL, "uint64_t");
+    if (pstate != NULL)
+        SCReturnCT(pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1], "uint64_t");
 
-    SCReturnCT(pstate->inspect_id[(direction & STREAM_TOSERVER) ? 0 : 1], "uint64_t");
+    DEBUG_VALIDATE_BUG_ON(1);
+    SCReturnCT(0ULL, "uint64_t");
 }
 
 inline uint64_t AppLayerParserGetTxDetectFlags(AppLayerTxData *txd, const uint8_t dir)