findJsonbValueFromSuperHeaderLen() lives in jsonfuncs.c
authorPeter Geoghegan <[email protected]>
Sun, 16 Mar 2014 03:54:23 +0000 (20:54 -0700)
committerPeter Geoghegan <[email protected]>
Sun, 16 Mar 2014 03:54:23 +0000 (20:54 -0700)
src/backend/utils/adt/jsonb_op.c
src/backend/utils/adt/jsonb_util.c
src/backend/utils/adt/jsonfuncs.c
src/include/utils/jsonb.h

index b22c8bcbd389e2d8d184f0994306459cd46d5a8f..708752189e9c08aeab299291696d7cdb74dc8f5c 100644 (file)
@@ -25,12 +25,17 @@ jsonb_exists(PG_FUNCTION_ARGS)
    text       *key = PG_GETARG_TEXT_PP(1);
    JsonbValue *v = NULL;
 
+   JsonbValue  kval;
+
+   kval.type = jbvString;
+   kval.string.val = VARDATA_ANY(key);
+   kval.string.len = VARSIZE_ANY_EXHDR(key);
+
    if (!JB_ISEMPTY(jb))
-       v = findJsonbValueFromSuperHeaderLen(VARDATA(jb),
-                                            JB_FOBJECT | JB_FARRAY,
-                                            NULL,
-                                            VARDATA_ANY(key),
-                                            VARSIZE_ANY_EXHDR(key));
+       v = findJsonbValueFromSuperHeader(VARDATA(jb),
+                                         JB_FOBJECT | JB_FARRAY,
+                                         NULL,
+                                         &kval);
 
    PG_RETURN_BOOL(v != NULL);
 }
index 79aef81034c8f73e76d62d4d12c723fb613cab27..6f9985ab14f7ebbfe31a02776957d0e1a05f137f 100644 (file)
@@ -257,29 +257,6 @@ compareJsonbSuperHeaderValue(JsonbSuperHeader a, JsonbSuperHeader b)
    return res;
 }
 
-/*
- * findJsonbValueFromSuperHeader() wrapper that sets up JsonbValue key.
- */
-JsonbValue *
-findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader, uint32 flags,
-                                uint32 *lowbound, char *key, uint32 keylen)
-{
-   JsonbValue  v;
-
-   if (key == NULL)
-   {
-       v.type = jbvNull;
-   }
-   else
-   {
-       v.type = jbvString;
-       v.string.val = key;
-       v.string.len = keylen;
-   }
-
-   return findJsonbValueFromSuperHeader(sheader, flags, lowbound, &v);
-}
-
 /*
  * Find value in object (i.e. the value part of some key/value pair in an
  * object), or find a matching element in an array.  Do so on the basis on
index 004630c3ba00ab6bc082cb8f58aed7c80d0765ed..fcd9562120d6c84840c26aae4b314d68a8cbdaf8 100644 (file)
@@ -104,6 +104,12 @@ static void populate_recordset_array_element_start(void *state, bool isnull);
 /* worker function for populate_recordset and to_recordset */
 static inline Datum populate_recordset_worker(FunctionCallInfo fcinfo,
                          bool have_record_arg);
+/* Worker that takes care of common setup for us */
+static JsonbValue *findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader,
+                                                   uint32 flags,
+                                                   uint32 *lowbound,
+                                                   char *key,
+                                                   uint32 keylen);
 
 /* search type classification for json_get* functions */
 typedef enum
@@ -3040,3 +3046,27 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
        hashentry->val = _state->saved_scalar;
    }
 }
+
+/*
+ * findJsonbValueFromSuperHeader() wrapper that sets up JsonbValue key
+ * according to our frequent requirements.
+ */
+static JsonbValue *
+findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader, uint32 flags,
+                                uint32 *lowbound, char *key, uint32 keylen)
+{
+   JsonbValue  k;
+
+   if (key == NULL)
+   {
+       k.type = jbvNull;
+   }
+   else
+   {
+       k.type = jbvString;
+       k.string.val = key;
+       k.string.len = keylen;
+   }
+
+   return findJsonbValueFromSuperHeader(sheader, flags, lowbound, &k);
+}
index d23cd5847751354160051a3d7d0c6bf064cce22e..e0e40242533eeff3d32f0d13bfddffba7a2df02c 100644 (file)
@@ -288,10 +288,6 @@ extern Datum gin_consistent_jsonb_hash(PG_FUNCTION_ARGS);
 /* Support functions */
 extern int compareJsonbSuperHeaderValue(JsonbSuperHeader a,
                                         JsonbSuperHeader b);
-extern JsonbValue *findJsonbValueFromSuperHeaderLen(JsonbSuperHeader sheader,
-                                                   uint32 flags,
-                                                   uint32 *lowbound,
-                                                   char *key, uint32 keylen);
 extern JsonbValue *findJsonbValueFromSuperHeader(JsonbSuperHeader sheader,
                                                 uint32 flags,
                                                 uint32 *lowbound,