Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 240c58b

Browse files
author
Nikita Glukhov
committed
Add jsonpath JsonbInitBinary()
1 parent cb1dded commit 240c58b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
149149
return lfirst(it->lcell);
150150
}
151151

152+
static inline JsonbValue *
153+
JsonbInitBinary(JsonbValue *jbv, Jsonb *jb)
154+
{
155+
jbv->type = jbvBinary;
156+
jbv->val.binary.data = &jb->root;
157+
jbv->val.binary.len = VARSIZE_ANY_EXHDR(jb);
158+
159+
return jbv;
160+
}
161+
152162
/********************Execute functions for JsonPath***************************/
153163

154164
/*
@@ -251,11 +261,7 @@ computeJsonPathVariable(JsonPathItem *variable, List *vars, JsonbValue *value)
251261
if (JB_ROOT_IS_SCALAR(jb))
252262
JsonbExtractScalar(&jb->root, value);
253263
else
254-
{
255-
value->type = jbvBinary;
256-
value->val.binary.data = &jb->root;
257-
value->val.binary.len = VARSIZE_ANY_EXHDR(jb);
258-
}
264+
JsonbInitBinary(value, jb);
259265
}
260266
break;
261267
default:
@@ -1896,8 +1902,7 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
18961902

18971903
jsonb = JsonbValueToJsonb(keyval);
18981904

1899-
obj.val.binary.data = &jsonb->root;
1900-
obj.val.binary.len = VARSIZE(jsonb) - VARHDRSZ;
1905+
JsonbInitBinary(&obj, jsonb);
19011906

19021907
res = recursiveExecuteNext(cxt, jsp, &elem, &obj, found, true);
19031908

@@ -2048,15 +2053,11 @@ executeJsonPath(JsonPath *path, List *vars, Jsonb *json, JsonValueList *foundJso
20482053
JsonPathItem jsp;
20492054
JsonbValue jbv;
20502055

2051-
jbv.type = jbvBinary;
2052-
jbv.val.binary.data = &json->root;
2053-
jbv.val.binary.len = VARSIZE_ANY_EXHDR(json);
2054-
20552056
jspInit(&jsp, path);
20562057

20572058
cxt.vars = vars;
20582059
cxt.lax = (path->header & JSONPATH_LAX) != 0;
2059-
cxt.root = &jbv;
2060+
cxt.root = JsonbInitBinary(&jbv, json);
20602061
cxt.innermostArraySize = -1;
20612062

20622063
if (!cxt.lax && !foundJson)

0 commit comments

Comments
 (0)