Remove == true idiom
authorPeter Geoghegan <[email protected]>
Wed, 12 Mar 2014 02:30:23 +0000 (19:30 -0700)
committerPeter Geoghegan <[email protected]>
Wed, 12 Mar 2014 02:30:23 +0000 (19:30 -0700)
src/backend/utils/adt/jsonb.c
src/backend/utils/adt/jsonb_support.c

index 3852e8dc74ecb26003c284a1627e71120ea1d914..3294b8d2367908dd3da6cb5bd7d06d3341f8bf55 100644 (file)
@@ -388,16 +388,16 @@ JsonbToCString(StringInfo out, char *in, int estimated_len)
        switch (type)
        {
            case WJB_BEGIN_ARRAY:
-               if (first == false)
+               if (!first)
                    appendBinaryStringInfo(out, ", ", 2);
                first = true;
 
-               if (v.array.scalar == false)
+               if (!v.array.scalar)
                    appendStringInfoChar(out, '[');
                level++;
                break;
            case WJB_BEGIN_OBJECT:
-               if (first == false)
+               if (!first)
                    appendBinaryStringInfo(out, ", ", 2);
                first = true;
                appendStringInfoCharMacro(out, '{');
@@ -405,7 +405,7 @@ JsonbToCString(StringInfo out, char *in, int estimated_len)
                level++;
                break;
            case WJB_KEY:
-               if (first == false)
+               if (!first)
                    appendBinaryStringInfo(out, ", ", 2);
                first = true;
 
@@ -432,7 +432,7 @@ JsonbToCString(StringInfo out, char *in, int estimated_len)
                }
                break;
            case WJB_ELEM:
-               if (first == false)
+               if (!first)
                    appendBinaryStringInfo(out, ", ", 2);
                else
                    first = false;
@@ -441,7 +441,7 @@ JsonbToCString(StringInfo out, char *in, int estimated_len)
                break;
            case WJB_END_ARRAY:
                level--;
-               if (v.array.scalar == false)
+               if (!v.array.scalar)
                    appendStringInfoChar(out, ']');
                first = false;
                break;
index 659c224cfad2ed966a31d7ec62c5edc7972d914b..5428e5a9ec0bf0b3f7bcebb2cd5e4733becc4b95 100644 (file)
@@ -382,8 +382,8 @@ findUncompressedJsonbValueByValue(char *buffer, uint32 flags,
            }
            else if (JBE_ISBOOL(*e) && key->type == jbvBool)
            {
-               if ((JBE_ISBOOL_TRUE(*e) && key->boolean == true) ||
-                   (JBE_ISBOOL_FALSE(*e) && key->boolean == false))
+               if ((JBE_ISBOOL_TRUE(*e) && key->boolean) ||
+                   (JBE_ISBOOL_FALSE(*e) && !key->boolean))
                {
                    r = *key;
                    r.size = sizeof(JEntry);
@@ -395,12 +395,14 @@ findUncompressedJsonbValueByValue(char *buffer, uint32 flags,
            }
            else if (JBE_ISNUMERIC(*e) && key->type == jbvNumeric)
            {
+               Numeric entry = (Numeric) (data + INTALIGN(JBE_OFF(*e)));
+
                if (DatumGetBool(DirectFunctionCall2(numeric_eq,
-                                                    PointerGetDatum(data + INTALIGN(JBE_OFF(*e))),
-                                                    PointerGetDatum(key->numeric))) == true)
+                                                    PointerGetDatum(entry),
+                                                    PointerGetDatum(key->numeric))))
                {
                    r.type = jbvNumeric;
-                   r.numeric = (Numeric) (data + INTALIGN(JBE_OFF(*e)));
+                   r.numeric = entry;
 
                    if (lowbound)
                        *lowbound = i;
@@ -418,13 +420,16 @@ findUncompressedJsonbValueByValue(char *buffer, uint32 flags,
                    stopHigh = (header & JB_COUNT_MASK),
                    stopMiddle;
 
-       if (key->type != jbvString)
-           return NULL;
+       /* Object keys must be strings */
+       Assert(key->type == jbvString);
 
+       /*
+        * Binary search for matching jsonb value
+        */
        while (stopLow < stopHigh)
        {
-           int         difference;
-           JEntry     *e;
+           JEntry *e;
+           int     difference;
 
            stopMiddle = stopLow + (stopHigh - stopLow) / 2;
 
@@ -608,7 +613,7 @@ getJsonbValue(char *buffer, uint32 flags, int32 i)
  * the passed object's key values.  Otherwise, they are assumed to already be
  * sorted and unique.
  *
- * Initial state of ToJsonbState is NULL.
+ * Initial state of *ToJsonbState is NULL.
  */
 JsonbValue *
 pushJsonbValue(ToJsonbState ** state, int r, JsonbValue * v)
@@ -869,7 +874,7 @@ parseBuffer(JsonbIterator * it, char *buffer)
        case JB_FLAG_ARRAY:
            it->data = buffer + it->nelems * sizeof(JEntry);
            it->isScalar = (header & JB_FLAG_SCALAR) != 0;
-           Assert(it->isScalar == false || it->nelems == 1);
+           Assert(!it->isScalar || it->nelems == 1);
            break;
        case JB_FLAG_OBJECT:
            it->data = buffer + it->nelems * sizeof(JEntry) * 2;