Skip to content

Commit

Permalink
app-layer: optimize pstate check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
victorjulien committed Jan 15, 2025
1 parent 6529365 commit 8cec882
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app-layer-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8cec882

Please sign in to comment.