Skip to content

Commit

Permalink
Fix branch prediction in Ensure
Browse files Browse the repository at this point in the history
PR #6648 introduces a branch prediction in the Ensure macro. However,
the checked condition needs to be negated to be unlikely. Therefore, the
check predicts the branch likelihood wrongly. In other words, reporting
an error in Ensure should be the unlikely case, and the condition should
be fulfilled in most calls. This commit fixes the branch prediction.
  • Loading branch information
jnidzwetzki committed Feb 22, 2024
1 parent 0d48019 commit 59a2640
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/debug_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define Ensure(COND, FMT, ...) \
do \
{ \
if (!unlikely(COND)) \
if (unlikely(!(COND))) \
ereport(ERROR, \
(errcode(ERRCODE_INTERNAL_ERROR), \
errdetail("Assertion '" #COND "' failed."), \
Expand Down

0 comments on commit 59a2640

Please sign in to comment.