Skip to content

Commit a7de1c7

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

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed

src/backend/utils/adt/jsonfuncs.c

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ static JsonbValue *setPath(JsonbIterator **it, Datum *path_elems,
452452
bool *path_nulls, int path_len,
453453
JsonbParseState **st, int level, Jsonb *newval,
454454
int op_type);
455-
static void setPathObject(JsonbIterator **it, Datum *path_elems,
455+
static JsonbIteratorToken setPathObject(JsonbIterator **it, Datum *path_elems,
456456
bool *path_nulls, int path_len, JsonbParseState **st,
457457
int level,
458-
Jsonb *newval, uint32 npairs, int op_type);
458+
Jsonb *newval, int op_type);
459459
static void setPathArray(JsonbIterator **it, Datum *path_elems,
460460
bool *path_nulls, int path_len, JsonbParseState **st,
461461
int level, Jsonb *newval, uint32 nelems, int op_type);
@@ -4550,9 +4550,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
45504550
break;
45514551
case WJB_BEGIN_OBJECT:
45524552
(void) pushJsonbValue(st, r, NULL);
4553-
setPathObject(it, path_elems, path_nulls, path_len, st, level,
4554-
newval, v.val.object.nPairs, op_type);
4555-
r = JsonbIteratorNext(it, &v, true);
4553+
r = setPathObject(it, path_elems, path_nulls, path_len, st, level,
4554+
newval, op_type);
45564555
Assert(r == WJB_END_OBJECT);
45574556
res = pushJsonbValue(st, r, NULL);
45584557
break;
@@ -4572,39 +4571,21 @@ setPath(JsonbIterator **it, Datum *path_elems,
45724571
/*
45734572
* Object walker for setPath
45744573
*/
4575-
static void
4574+
static JsonbIteratorToken
45764575
setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
45774576
int path_len, JsonbParseState **st, int level,
4578-
Jsonb *newval, uint32 npairs, int op_type)
4577+
Jsonb *newval, int op_type)
45794578
{
45804579
JsonbValue v;
4581-
int i;
45824580
JsonbValue k;
4581+
JsonbIteratorToken r;
45834582
bool done = false;
45844583

45854584
if (level >= path_len || path_nulls[level])
45864585
done = true;
45874586

4588-
/* empty object is a special case for create */
4589-
if ((npairs == 0) && (op_type & JB_PATH_CREATE_OR_INSERT) &&
4590-
(level == path_len - 1))
4587+
while ((r = JsonbIteratorNext(it, &k, true)) == WJB_KEY)
45914588
{
4592-
JsonbValue newkey;
4593-
4594-
newkey.type = jbvString;
4595-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4596-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4597-
4598-
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4599-
addJsonbToParseState(st, newval);
4600-
}
4601-
4602-
for (i = 0; i < npairs; i++)
4603-
{
4604-
JsonbIteratorToken r = JsonbIteratorNext(it, &k, true);
4605-
4606-
Assert(r == WJB_KEY);
4607-
46084589
if (!done &&
46094590
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
46104591
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
@@ -4624,6 +4605,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
46244605
"to replace key value.")));
46254606

46264607
r = JsonbIteratorNext(it, &v, true); /* skip value */
4608+
Assert(r == WJB_VALUE);
4609+
46274610
if (!(op_type & JB_PATH_DELETE))
46284611
{
46294612
(void) pushJsonbValue(st, WJB_KEY, &k);
@@ -4640,25 +4623,26 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
46404623
}
46414624
else
46424625
{
4643-
if ((op_type & JB_PATH_CREATE_OR_INSERT) && !done &&
4644-
level == path_len - 1 && i == npairs - 1)
4645-
{
4646-
JsonbValue newkey;
4647-
4648-
newkey.type = jbvString;
4649-
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4650-
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4651-
4652-
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4653-
addJsonbToParseState(st, newval);
4654-
}
4655-
46564626
(void) pushJsonbValue(st, r, &k);
46574627
r = JsonbIteratorNext(it, &v, true);
46584628
Assert(r == WJB_VALUE);
46594629
(void) pushJsonbValue(st, r, &v);
46604630
}
46614631
}
4632+
4633+
if ((op_type & JB_PATH_CREATE_OR_INSERT) && !done && level == path_len - 1)
4634+
{
4635+
JsonbValue newkey;
4636+
4637+
newkey.type = jbvString;
4638+
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
4639+
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
4640+
4641+
(void) pushJsonbValue(st, WJB_KEY, &newkey);
4642+
addJsonbToParseState(st, newval);
4643+
}
4644+
4645+
return r;
46624646
}
46634647

46644648
/*

0 commit comments

Comments
 (0)