1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-25 20:23:07 +03:00

Add repalloc0 and repalloc0_array

These zero out the space added by repalloc.  This is a common pattern
that is quite hairy to code by hand.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/b66dfc89-9365-cb57-4e1f-b7d31813eeec@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-11-12 20:31:27 +01:00
parent 30d98e14a8
commit b4b7ce8061
10 changed files with 48 additions and 71 deletions

View File

@@ -133,16 +133,11 @@ find_placeholder_info(PlannerInfo *root, PlaceHolderVar *phv)
while (phinfo->phid >= new_size)
new_size *= 2;
if (root->placeholder_array)
{
root->placeholder_array = (PlaceHolderInfo **)
repalloc(root->placeholder_array,
sizeof(PlaceHolderInfo *) * new_size);
MemSet(root->placeholder_array + root->placeholder_array_size, 0,
sizeof(PlaceHolderInfo *) * (new_size - root->placeholder_array_size));
}
root->placeholder_array =
repalloc0_array(root->placeholder_array, PlaceHolderInfo *, root->placeholder_array_size, new_size);
else
root->placeholder_array = (PlaceHolderInfo **)
palloc0(new_size * sizeof(PlaceHolderInfo *));
root->placeholder_array =
palloc0_array(PlaceHolderInfo *, new_size);
root->placeholder_array_size = new_size;
}
root->placeholder_array[phinfo->phid] = phinfo;

View File

@@ -157,31 +157,18 @@ expand_planner_arrays(PlannerInfo *root, int add_size)
new_size = root->simple_rel_array_size + add_size;
root->simple_rel_array = (RelOptInfo **)
repalloc(root->simple_rel_array,
sizeof(RelOptInfo *) * new_size);
MemSet(root->simple_rel_array + root->simple_rel_array_size,
0, sizeof(RelOptInfo *) * add_size);
root->simple_rel_array =
repalloc0_array(root->simple_rel_array, RelOptInfo *, root->simple_rel_array_size, new_size);
root->simple_rte_array = (RangeTblEntry **)
repalloc(root->simple_rte_array,
sizeof(RangeTblEntry *) * new_size);
MemSet(root->simple_rte_array + root->simple_rel_array_size,
0, sizeof(RangeTblEntry *) * add_size);
root->simple_rte_array =
repalloc0_array(root->simple_rte_array, RangeTblEntry *, root->simple_rel_array_size, new_size);
if (root->append_rel_array)
{
root->append_rel_array = (AppendRelInfo **)
repalloc(root->append_rel_array,
sizeof(AppendRelInfo *) * new_size);
MemSet(root->append_rel_array + root->simple_rel_array_size,
0, sizeof(AppendRelInfo *) * add_size);
}
root->append_rel_array =
repalloc0_array(root->append_rel_array, AppendRelInfo *, root->simple_rel_array_size, new_size);
else
{
root->append_rel_array = (AppendRelInfo **)
palloc0(sizeof(AppendRelInfo *) * new_size);
}
root->append_rel_array =
palloc0_array(AppendRelInfo *, new_size);
root->simple_rel_array_size = new_size;
}