Skip to content

Commit 5d43d5c

Browse files
author
Nikita Glukhov
committed
Add JsonValueInitBinary()
1 parent e70f462 commit 5d43d5c

File tree

5 files changed

+16
-29
lines changed

5 files changed

+16
-29
lines changed

src/backend/utils/adt/json_generic.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ JsonToJsonValue(Json *json, JsonValue *jv)
6565
if (!jv)
6666
jv = palloc(sizeof(JsonValue));
6767

68-
jv->type = jbvBinary;
69-
jv->val.binary.data = &json->root;
70-
71-
return jv;
68+
return JsonValueInitBinary(jv, &json->root);
7269
}
7370

7471
static void

src/backend/utils/adt/jsonb_util.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ JsonContainerFlatten(JsonContainer *jc, JsonValueEncoder encoder,
135135
if (binary)
136136
Assert(binary->type == jbvBinary);
137137
else
138-
{
139-
jbv.type = jbvBinary;
140-
jbv.val.binary.data = jc;
141-
142-
binary = &jbv;
143-
}
138+
binary = JsonValueInitBinary(&jbv, jc);
144139

145140
return convertToJsonb(binary, encoder);
146141
}

src/backend/utils/adt/jsonfuncs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,8 +3475,7 @@ populate_record_worker(FunctionCallInfo fcinfo, const char *funcname,
34753475
jsv.val.jsonb = &jbv;
34763476

34773477
/* fill binary jsonb value pointing to jb */
3478-
jbv.type = jbvBinary;
3479-
jbv.val.binary.data = &jb->root;
3478+
JsonValueInitBinary(&jbv, JsonRoot(jb));
34803479
}
34813480

34823481
rettuple = populate_composite(&cache->c.io.composite, cache->argtype,

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ static void JsonValueListInitIterator(const JsonValueList *jvl,
313313
static JsonbValue *JsonValueListNext(const JsonValueList *jvl,
314314
JsonValueListIterator *it);
315315
static int JsonbType(JsonbValue *jb);
316-
static JsonbValue *JsonbInitBinary(JsonbValue *jbv, Jsonb *jb);
317316
static int JsonbType(JsonbValue *jb);
318317
static JsonbValue *getScalar(JsonbValue *scalar, enum jbvType type);
319318
static JsonbValue *wrapItemsInArray(const JsonValueList *items);
@@ -625,7 +624,7 @@ executeJsonPath(JsonPath *path, void *vars, JsonPathVarCallback getVar,
625624
jspInit(&jsp, path);
626625

627626
if (!JsonbExtractScalar(&json->root, &jbv))
628-
JsonbInitBinary(&jbv, json);
627+
JsonValueInitBinary(&jbv, JsonRoot(json));
629628

630629
cxt.vars = vars;
631630
cxt.getVar = getVar;
@@ -2093,7 +2092,7 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
20932092

20942093
jsonb = JsonbValueToJsonb(keyval);
20952094

2096-
JsonbInitBinary(&obj, jsonb);
2095+
JsonValueInitBinary(&obj, JsonRoot(jsonb));
20972096

20982097
baseObject = setBaseObject(cxt, &obj, cxt->lastGeneratedObjectId++);
20992098

@@ -2233,7 +2232,7 @@ getJsonPathVariableFromJsonb(void *varsJsonb, char *varName, int varNameLength,
22332232
*value = *v;
22342233
pfree(v);
22352234

2236-
JsonbInitBinary(baseObject, vars);
2235+
JsonValueInitBinary(baseObject, JsonRoot(vars));
22372236
return 1;
22382237
}
22392238

@@ -2615,18 +2614,6 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
26152614
return result;
26162615
}
26172616

2618-
/*
2619-
* Initialize a binary JsonbValue with the given jsonb container.
2620-
*/
2621-
static JsonbValue *
2622-
JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
2623-
{
2624-
jbv->type = jbvBinary;
2625-
jbv->val.binary.data = &jb->root;
2626-
2627-
return jbv;
2628-
}
2629-
26302617
/*
26312618
* Returns jbv* type of JsonbValue. Note, it never returns jbvBinary as is.
26322619
*/
@@ -3115,7 +3102,7 @@ JsonItemFromDatum(Datum val, Oid typid, int32 typmod, JsonbValue *res)
31153102
Assert(res);
31163103
}
31173104
else
3118-
JsonbInitBinary(jbv, jb);
3105+
JsonValueInitBinary(jbv, JsonRoot(jb));
31193106
break;
31203107
}
31213108
case JSONOID:

src/include/utils/json_generic.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ JsonIteratorFree(JsonIterator *it)
231231
it = JsonIteratorFreeAndGetParent(it);
232232
}
233233

234+
static inline JsonValue *
235+
JsonValueInitBinary(JsonValue *val, JsonContainer *cont)
236+
{
237+
val->type = jbvBinary;
238+
val->val.binary.data = cont;
239+
240+
return val;
241+
}
242+
234243
extern Json *JsonValueToJson(JsonValue *val);
235244
extern JsonValue *JsonToJsonValue(Json *json, JsonValue *jv);
236245
extern JsonValue *JsonValueUnpackBinary(const JsonValue *jbv);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy