Skip to content

Commit 72ca9c3

Browse files
author
Nikita Glukhov
committed
Remove JsonbValue.val.object.nPairs references outside of jsonb_uitls.c
1 parent 5840317 commit 72ca9c3

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems,
466466
int op_type);
467467
static void setPathObject(JsonbIterator **it, Datum *path_elems,
468468
bool *path_nulls, int path_len, JsonbParseState **st,
469-
int level,
470-
Jsonb *newval, uint32 npairs, int op_type);
469+
int level, Jsonb *newval, int op_type);
471470
static void setPathArray(JsonbIterator **it, Datum *path_elems,
472471
bool *path_nulls, int path_len, JsonbParseState **st,
473472
int level, Jsonb *newval, uint32 nelems, int op_type);
@@ -4822,9 +4821,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
48224821
break;
48234822
case WJB_BEGIN_OBJECT:
48244823
(void) pushJsonbValue(st, r, NULL);
4825-
setPathObject(it, path_elems, path_nulls, path_len, st, level,
4826-
newval, v.val.object.nPairs, op_type);
4827-
r = JsonbIteratorNext(it, &v, true);
4824+
r = setPathObject(it, path_elems, path_nulls, path_len, st, level,
4825+
newval, op_type);
48284826
Assert(r == WJB_END_OBJECT);
48294827
res = pushJsonbValue(st, r, NULL);
48304828
break;
@@ -4844,39 +4842,21 @@ setPath(JsonbIterator **it, Datum *path_elems,
48444842
/*
48454843
* Object walker for setPath
48464844
*/
4847-
static void
4845+
static JsonbIteratorToken
48484846
setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
48494847
int path_len, JsonbParseState **st, int level,
4850-
Jsonb *newval, uint32 npairs, int op_type)
4848+
Jsonb *newval, int op_type)
48514849
{
48524850
JsonbValue v;
4853-
int i;
48544851
JsonbValue k;
4852+
JsonbIteratorToken r;
48554853
bool done = false;
48564854

48574855
if (level >= path_len || path_nulls[level])
48584856
done = true;
48594857

4860-
/* empty object is a special case for create */
4861-
if ((npairs == 0) && (op_type & JB_PATH_CREATE_OR_INSERT) &&
4862-
(level == path_len - 1))
4858+
while ((r = JsonbIteratorNext(it, &k, true)) == WJB_KEY)
48634859
{
4864-
JsonbValue newkey;
4865-
4866-
newkey.type = jbvString;
4867-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4868-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4869-
4870-
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4871-
addJsonbToParseState(st, newval);
4872-
}
4873-
4874-
for (i = 0; i < npairs; i++)
4875-
{
4876-
JsonbIteratorToken r = JsonbIteratorNext(it, &k, true);
4877-
4878-
Assert(r == WJB_KEY);
4879-
48804860
if (!done &&
48814861
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
48824862
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
@@ -4896,6 +4876,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
48964876
"to replace key value.")));
48974877

48984878
r = JsonbIteratorNext(it, &v, true); /* skip value */
4879+
Assert(r == WJB_VALUE);
4880+
48994881
if (!(op_type & JB_PATH_DELETE))
49004882
{
49014883
(void) pushJsonbValue(st, WJB_KEY, &k);
@@ -4912,25 +4894,26 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
49124894
}
49134895
else
49144896
{
4915-
if ((op_type & JB_PATH_CREATE_OR_INSERT) && !done &&
4916-
level == path_len - 1 && i == npairs - 1)
4917-
{
4918-
JsonbValue newkey;
4919-
4920-
newkey.type = jbvString;
4921-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4922-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4923-
4924-
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4925-
addJsonbToParseState(st, newval);
4926-
}
4927-
49284897
(void) pushJsonbValue(st, r, &k);
49294898
r = JsonbIteratorNext(it, &v, true);
49304899
Assert(r == WJB_VALUE);
49314900
(void) pushJsonbValue(st, r, &v);
49324901
}
49334902
}
4903+
4904+
if ((op_type & JB_PATH_CREATE_OR_INSERT) && !done && level == path_len - 1)
4905+
{
4906+
JsonbValue newkey;
4907+
4908+
newkey.type = jbvString;
4909+
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4910+
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4911+
4912+
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4913+
addJsonbToParseState(st, newval);
4914+
}
4915+
4916+
return r;
49344917
}
49354918

49364919
/*

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