Get rid of unnecessary memory allocation in jsonb_subscript_assign()

Current code allocates memory for JsonbValue, but it could be placed locally.
This commit is contained in:
Alexander Korotkov 2021-02-01 14:06:02 +03:00
parent fe61df7f82
commit bb513b364b
1 changed files with 7 additions and 7 deletions

View File

@ -283,7 +283,7 @@ jsonb_subscript_assign(ExprState *state,
*/
if (*op->resnull)
{
JsonbValue *newSource = (JsonbValue *) palloc(sizeof(JsonbValue));
JsonbValue newSource;
/*
* To avoid any surprising results, set up an empty jsonb array in
@ -292,17 +292,17 @@ jsonb_subscript_assign(ExprState *state,
*/
if (workspace->expectArray)
{
newSource->type = jbvArray;
newSource->val.array.nElems = 0;
newSource->val.array.rawScalar = false;
newSource.type = jbvArray;
newSource.val.array.nElems = 0;
newSource.val.array.rawScalar = false;
}
else
{
newSource->type = jbvObject;
newSource->val.object.nPairs = 0;
newSource.type = jbvObject;
newSource.val.object.nPairs = 0;
}
jsonbSource = JsonbValueToJsonb(newSource);
jsonbSource = JsonbValueToJsonb(&newSource);
*op->resnull = false;
}
else