Skip to content

Commit bb513b3

Browse files
committed
Get rid of unnecessary memory allocation in jsonb_subscript_assign()
Current code allocates memory for JsonbValue, but it could be placed locally.
1 parent fe61df7 commit bb513b3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/backend/utils/adt/jsonbsubs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ jsonb_subscript_assign(ExprState *state,
283283
*/
284284
if (*op->resnull)
285285
{
286-
JsonbValue *newSource = (JsonbValue *) palloc(sizeof(JsonbValue));
286+
JsonbValue newSource;
287287

288288
/*
289289
* To avoid any surprising results, set up an empty jsonb array in
@@ -292,17 +292,17 @@ jsonb_subscript_assign(ExprState *state,
292292
*/
293293
if (workspace->expectArray)
294294
{
295-
newSource->type = jbvArray;
296-
newSource->val.array.nElems = 0;
297-
newSource->val.array.rawScalar = false;
295+
newSource.type = jbvArray;
296+
newSource.val.array.nElems = 0;
297+
newSource.val.array.rawScalar = false;
298298
}
299299
else
300300
{
301-
newSource->type = jbvObject;
302-
newSource->val.object.nPairs = 0;
301+
newSource.type = jbvObject;
302+
newSource.val.object.nPairs = 0;
303303
}
304304

305-
jsonbSource = JsonbValueToJsonb(newSource);
305+
jsonbSource = JsonbValueToJsonb(&newSource);
306306
*op->resnull = false;
307307
}
308308
else

0 commit comments

Comments
 (0)