]> granicus.if.org Git - postgresql/commitdiff
Improve implementation of EEOP_BOOLTEST_* opcodes.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 26 Mar 2017 19:57:02 +0000 (15:57 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 26 Mar 2017 19:57:02 +0000 (15:57 -0400)
Both Andres and I were happy with "*op->resvalue = *op->resvalue;",
but Coverity isn't; and it has a point, because some compilers might
not be smart enough to elide that.  So remove it.  In passing, also
avoid doing unnecessary assignments to *op->resnull when it's already
known to have the right value.

src/backend/executor/execExprInterp.c

index de7fe895f8153d3270041647fe84d6708f234022..02fb29cde3fd332e6a3c7bf59934652b0a18927c 100644 (file)
@@ -958,10 +958,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
                EEO_CASE(EEOP_BOOLTEST_IS_TRUE)
                {
                        if (*op->resnull)
+                       {
                                *op->resvalue = BoolGetDatum(false);
-                       else
-                               *op->resvalue = *op->resvalue;
-                       *op->resnull = false;
+                               *op->resnull = false;
+                       }
+                       /* else, input value is the correct output as well */
 
                        EEO_NEXT();
                }
@@ -969,10 +970,12 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
                EEO_CASE(EEOP_BOOLTEST_IS_NOT_TRUE)
                {
                        if (*op->resnull)
+                       {
                                *op->resvalue = BoolGetDatum(true);
+                               *op->resnull = false;
+                       }
                        else
                                *op->resvalue = BoolGetDatum(!DatumGetBool(*op->resvalue));
-                       *op->resnull = false;
 
                        EEO_NEXT();
                }
@@ -980,10 +983,12 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
                EEO_CASE(EEOP_BOOLTEST_IS_FALSE)
                {
                        if (*op->resnull)
+                       {
                                *op->resvalue = BoolGetDatum(false);
+                               *op->resnull = false;
+                       }
                        else
                                *op->resvalue = BoolGetDatum(!DatumGetBool(*op->resvalue));
-                       *op->resnull = false;
 
                        EEO_NEXT();
                }
@@ -991,10 +996,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
                EEO_CASE(EEOP_BOOLTEST_IS_NOT_FALSE)
                {
                        if (*op->resnull)
+                       {
                                *op->resvalue = BoolGetDatum(true);
-                       else
-                               *op->resvalue = *op->resvalue;
-                       *op->resnull = false;
+                               *op->resnull = false;
+                       }
+                       /* else, input value is the correct output as well */
 
                        EEO_NEXT();
                }