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

Commit cf22d8f

Browse files
author
Nikita Glukhov
committed
Add jsonpath JsonbInitBinary()
1 parent 99fa8bc commit cf22d8f

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
@@ -148,6 +148,16 @@ JsonValueListNext(const JsonValueList *jvl, JsonValueListIterator *it)
148148
return lfirst(it->lcell);
149149
}
150150

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

153163
/*
@@ -250,11 +260,7 @@ computeJsonPathVariable(JsonPathItem *variable, List *vars, JsonbValue *value)
250260
if (JB_ROOT_IS_SCALAR(jb))
251261
JsonbExtractScalar(&jb->root, value);
252262
else
253-
{
254-
value->type = jbvBinary;
255-
value->val.binary.data = &jb->root;
256-
value->val.binary.len = VARSIZE_ANY_EXHDR(jb);
257-
}
263+
JsonbInitBinary(value, jb);
258264
}
259265
break;
260266
default:
@@ -1728,8 +1734,7 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
17281734

17291735
jsonb = JsonbValueToJsonb(keyval);
17301736

1731-
obj.val.binary.data = &jsonb->root;
1732-
obj.val.binary.len = VARSIZE(jsonb) - VARHDRSZ;
1737+
JsonbInitBinary(&obj, jsonb);
17331738

17341739
res = recursiveExecuteNext(cxt, jsp, &elem, &obj, found, true);
17351740

@@ -1855,15 +1860,11 @@ executeJsonPath(JsonPath *path, List *vars, Jsonb *json, JsonValueList *foundJso
18551860
JsonPathItem jsp;
18561861
JsonbValue jbv;
18571862

1858-
jbv.type = jbvBinary;
1859-
jbv.val.binary.data = &json->root;
1860-
jbv.val.binary.len = VARSIZE_ANY_EXHDR(json);
1861-
18621863
jspInit(&jsp, path);
18631864

18641865
cxt.vars = vars;
18651866
cxt.lax = (path->header & JSONPATH_LAX) != 0;
1866-
cxt.root = &jbv;
1867+
cxt.root = JsonbInitBinary(&jbv, json);
18671868
cxt.innermostArraySize = -1;
18681869

18691870
return recursiveExecute(&cxt, &jsp, &jbv, foundJson);

0 commit comments

Comments
 (0)