findJsonbValueFromSuperHeader() primitive type ordering
authorPeter Geoghegan <pg@heroku.com>
Mon, 17 Mar 2014 22:30:55 +0000 (15:30 -0700)
committerPeter Geoghegan <pg@heroku.com>
Mon, 17 Mar 2014 22:30:55 +0000 (15:30 -0700)
src/backend/utils/adt/jsonb_util.c

index 470825d62fca872d4d5e55d6c1484d1d57eae3aa..4812c02feb7415dea7fbc455e187c01e863af4a0 100644 (file)
@@ -314,9 +314,9 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
            if (JBE_ISNULL(*e) && key->type == jbvNull)
            {
                r->type = jbvNull;
+               r->estSize = sizeof(JEntry);
                if (lowbound)
                    *lowbound = i;
-               r->estSize = sizeof(JEntry);
 
                return r;
            }
@@ -337,20 +337,6 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
                    return r;
                }
            }
-           else if (JBE_ISBOOL(*e) && key->type == jbvBool)
-           {
-               if ((JBE_ISBOOL_TRUE(*e) && key->boolean) ||
-                   (JBE_ISBOOL_FALSE(*e) && !key->boolean))
-               {
-                   /* Deep copy */
-                   *r = *key;
-                   r->estSize = sizeof(JEntry);
-                   if (lowbound)
-                       *lowbound = i;
-
-                   return r;
-               }
-           }
            else if (JBE_ISNUMERIC(*e) && key->type == jbvNumeric)
            {
                Numeric entry = (Numeric) (data + INTALIGN(JBE_OFF(*e)));
@@ -361,7 +347,20 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
                {
                    r->type = jbvNumeric;
                    r->numeric = entry;
+                   if (lowbound)
+                       *lowbound = i;
 
+                   return r;
+               }
+           }
+           else if (JBE_ISBOOL(*e) && key->type == jbvBool)
+           {
+               if ((JBE_ISBOOL_TRUE(*e) && key->boolean) ||
+                   (JBE_ISBOOL_FALSE(*e) && !key->boolean))
+               {
+                   r->type = jbvBool;
+                   r->boolean = JBE_ISBOOL_TRUE(*e) != 0;
+                   r->estSize = sizeof(JEntry);
                    if (lowbound)
                        *lowbound = i;
 
@@ -414,19 +413,18 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
                if (lowbound)
                    *lowbound = stopMiddle + 1;
 
-               if (JBE_ISSTRING(*v))
+               if (JBE_ISNULL(*v))
+               {
+                   r->type = jbvNull;
+                   r->estSize = sizeof(JEntry);
+               }
+               else if (JBE_ISSTRING(*v))
                {
                    r->type = jbvString;
                    r->string.val = data + JBE_OFF(*v);
                    r->string.len = JBE_LEN(*v);
                    r->estSize = sizeof(JEntry) + r->string.len;
                }
-               else if (JBE_ISBOOL(*v))
-               {
-                   r->type = jbvBool;
-                   r->boolean = JBE_ISBOOL_TRUE(*v) != 0;
-                   r->estSize = sizeof(JEntry);
-               }
                else if (JBE_ISNUMERIC(*v))
                {
                    r->type = jbvNumeric;
@@ -434,16 +432,17 @@ findJsonbValueFromSuperHeader(JsonbSuperHeader sheader, uint32 flags,
 
                    r->estSize = 2 * sizeof(JEntry) + VARSIZE_ANY(r->numeric);
                }
-               else if (JBE_ISNULL(*v))
+               else if (JBE_ISBOOL(*v))
                {
-                   r->type = jbvNull;
+                   r->type = jbvBool;
+                   r->boolean = JBE_ISBOOL_TRUE(*v) != 0;
                    r->estSize = sizeof(JEntry);
                }
                else
                {
                    /*
-                    * See header comments to understand why this function
-                    * never does this for arrays
+                    * See header comments to understand why this never happens
+                    * with arrays
                     */
                    r->type = jbvBinary;
                    r->binary.data = data + INTALIGN(JBE_OFF(*v));