mirror of
https://github.com/postgres/postgres.git
synced 2025-12-18 05:01:01 +03:00
Use palloc_object() and palloc_array(), the last change
This is the last batch of changes that have been suggested by the author, this part covering the non-trivial changes. Some of the changes suggested have been discarded as they seem to lead to more instructions generated, leaving the parts that can be qualified as in-place replacements. Similar work has been done in1b105f9472,0c3c5c3b06and31d3847a37. Author: David Geier <geidav.pg@gmail.com> Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com
This commit is contained in:
@@ -134,7 +134,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
|
||||
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
||||
|
||||
/* Create a user function context for cross-call persistence */
|
||||
fctx = (BufferCachePagesContext *) palloc(sizeof(BufferCachePagesContext));
|
||||
fctx = palloc_object(BufferCachePagesContext);
|
||||
|
||||
/*
|
||||
* To smoothly support upgrades from version 1.0 of this extension
|
||||
@@ -382,8 +382,8 @@ pg_buffercache_os_pages_internal(FunctionCallInfo fcinfo, bool include_numa)
|
||||
os_page_count = (endptr - startptr) / os_page_size;
|
||||
|
||||
/* Used to determine the NUMA node for all OS pages at once */
|
||||
os_page_ptrs = palloc0(sizeof(void *) * os_page_count);
|
||||
os_page_status = palloc(sizeof(int) * os_page_count);
|
||||
os_page_ptrs = palloc0_array(void *, os_page_count);
|
||||
os_page_status = palloc_array(int, os_page_count);
|
||||
|
||||
/*
|
||||
* Fill pointers for all the memory pages. This loop stores and
|
||||
@@ -425,7 +425,7 @@ pg_buffercache_os_pages_internal(FunctionCallInfo fcinfo, bool include_numa)
|
||||
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
||||
|
||||
/* Create a user function context for cross-call persistence */
|
||||
fctx = (BufferCacheOsPagesContext *) palloc(sizeof(BufferCacheOsPagesContext));
|
||||
fctx = palloc_object(BufferCacheOsPagesContext);
|
||||
|
||||
if (get_call_result_type(fcinfo, NULL, &expected_tupledesc) != TYPEFUNC_COMPOSITE)
|
||||
elog(ERROR, "return type must be a row type");
|
||||
|
||||
@@ -452,7 +452,7 @@ make_positional_trgm(trgm *trg1, int len1, trgm *trg2, int len2)
|
||||
int i,
|
||||
len = len1 + len2;
|
||||
|
||||
result = (pos_trgm *) palloc(sizeof(pos_trgm) * len);
|
||||
result = palloc_array(pos_trgm, len);
|
||||
|
||||
for (i = 0; i < len1; i++)
|
||||
{
|
||||
@@ -535,7 +535,7 @@ iterate_word_similarity(int *trg2indexes,
|
||||
lower = (flags & WORD_SIMILARITY_STRICT) ? 0 : -1;
|
||||
|
||||
/* Memorise last position of each trigram */
|
||||
lastpos = (int *) palloc(sizeof(int) * len);
|
||||
lastpos = palloc_array(int, len);
|
||||
memset(lastpos, -1, sizeof(int) * len);
|
||||
|
||||
for (i = 0; i < len2; i++)
|
||||
@@ -711,8 +711,8 @@ calc_word_similarity(char *str1, int slen1, char *str2, int slen2,
|
||||
* Merge positional trigrams array: enumerate each trigram and find its
|
||||
* presence in required word.
|
||||
*/
|
||||
trg2indexes = (int *) palloc(sizeof(int) * len2);
|
||||
found = (bool *) palloc0(sizeof(bool) * len);
|
||||
trg2indexes = palloc_array(int, len2);
|
||||
found = palloc0_array(bool, len);
|
||||
|
||||
ulen1 = 0;
|
||||
j = 0;
|
||||
@@ -938,7 +938,7 @@ generate_wildcard_trgm(const char *str, int slen)
|
||||
tptr = GETARR(trg);
|
||||
|
||||
/* Allocate a buffer for blank-padded, but not yet case-folded, words */
|
||||
buf = palloc(sizeof(char) * (slen + 4));
|
||||
buf = palloc_array(char, slen + 4);
|
||||
|
||||
/*
|
||||
* Extract trigrams from each substring extracted by get_wildcard_part.
|
||||
@@ -1008,7 +1008,7 @@ show_trgm(PG_FUNCTION_ARGS)
|
||||
int i;
|
||||
|
||||
trg = generate_trgm(VARDATA_ANY(in), VARSIZE_ANY_EXHDR(in));
|
||||
d = (Datum *) palloc(sizeof(Datum) * (1 + ARRNELEM(trg)));
|
||||
d = palloc_array(Datum, 1 + ARRNELEM(trg));
|
||||
|
||||
for (i = 0, ptr = GETARR(trg); i < ARRNELEM(trg); i++, ptr++)
|
||||
{
|
||||
@@ -1136,7 +1136,7 @@ trgm_presence_map(TRGM *query, TRGM *key)
|
||||
lenk = ARRNELEM(key),
|
||||
i;
|
||||
|
||||
result = (bool *) palloc0(lenq * sizeof(bool));
|
||||
result = palloc0_array(bool, lenq);
|
||||
|
||||
/* for each query trigram, do a binary search in the key array */
|
||||
for (i = 0; i < lenq; i++)
|
||||
|
||||
@@ -633,7 +633,7 @@ postgresGetForeignRelSize(PlannerInfo *root,
|
||||
* We use PgFdwRelationInfo to pass various information to subsequent
|
||||
* functions.
|
||||
*/
|
||||
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
|
||||
fpinfo = palloc0_object(PgFdwRelationInfo);
|
||||
baserel->fdw_private = fpinfo;
|
||||
|
||||
/* Base foreign tables need to be pushed down always. */
|
||||
@@ -1517,7 +1517,7 @@ postgresBeginForeignScan(ForeignScanState *node, int eflags)
|
||||
/*
|
||||
* We'll save private state in node->fdw_state.
|
||||
*/
|
||||
fsstate = (PgFdwScanState *) palloc0(sizeof(PgFdwScanState));
|
||||
fsstate = palloc0_object(PgFdwScanState);
|
||||
node->fdw_state = fsstate;
|
||||
|
||||
/*
|
||||
@@ -2663,7 +2663,7 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
|
||||
/*
|
||||
* We'll save private state in node->fdw_state.
|
||||
*/
|
||||
dmstate = (PgFdwDirectModifyState *) palloc0(sizeof(PgFdwDirectModifyState));
|
||||
dmstate = palloc0_object(PgFdwDirectModifyState);
|
||||
node->fdw_state = dmstate;
|
||||
|
||||
/*
|
||||
@@ -3977,7 +3977,7 @@ create_foreign_modify(EState *estate,
|
||||
ListCell *lc;
|
||||
|
||||
/* Begin constructing PgFdwModifyState. */
|
||||
fmstate = (PgFdwModifyState *) palloc0(sizeof(PgFdwModifyState));
|
||||
fmstate = palloc0_object(PgFdwModifyState);
|
||||
fmstate->rel = rel;
|
||||
|
||||
/* Identify which user to do the remote access as. */
|
||||
@@ -4014,7 +4014,7 @@ create_foreign_modify(EState *estate,
|
||||
|
||||
/* Prepare for output conversion of parameters used in prepared stmt. */
|
||||
n_params = list_length(fmstate->target_attrs) + 1;
|
||||
fmstate->p_flinfo = (FmgrInfo *) palloc0(sizeof(FmgrInfo) * n_params);
|
||||
fmstate->p_flinfo = palloc0_array(FmgrInfo, n_params);
|
||||
fmstate->p_nums = 0;
|
||||
|
||||
if (operation == CMD_UPDATE || operation == CMD_DELETE)
|
||||
@@ -4814,7 +4814,7 @@ prepare_query_params(PlanState *node,
|
||||
Assert(numParams > 0);
|
||||
|
||||
/* Prepare for output conversion of parameters used in remote query. */
|
||||
*param_flinfo = (FmgrInfo *) palloc0(sizeof(FmgrInfo) * numParams);
|
||||
*param_flinfo = palloc0_array(FmgrInfo, numParams);
|
||||
|
||||
i = 0;
|
||||
foreach(lc, fdw_exprs)
|
||||
@@ -6297,7 +6297,7 @@ postgresGetForeignJoinPaths(PlannerInfo *root,
|
||||
* if found safe. Once we know that this join can be pushed down, we fill
|
||||
* the entry.
|
||||
*/
|
||||
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
|
||||
fpinfo = palloc0_object(PgFdwRelationInfo);
|
||||
fpinfo->pushdown_safe = false;
|
||||
joinrel->fdw_private = fpinfo;
|
||||
/* attrs_used is only for base relations. */
|
||||
@@ -6666,7 +6666,7 @@ postgresGetForeignUpperPaths(PlannerInfo *root, UpperRelationKind stage,
|
||||
output_rel->fdw_private)
|
||||
return;
|
||||
|
||||
fpinfo = (PgFdwRelationInfo *) palloc0(sizeof(PgFdwRelationInfo));
|
||||
fpinfo = palloc0_object(PgFdwRelationInfo);
|
||||
fpinfo->pushdown_safe = false;
|
||||
fpinfo->stage = stage;
|
||||
output_rel->fdw_private = fpinfo;
|
||||
@@ -6891,7 +6891,7 @@ add_foreign_ordered_paths(PlannerInfo *root, RelOptInfo *input_rel,
|
||||
fpinfo->pushdown_safe = true;
|
||||
|
||||
/* Construct PgFdwPathExtraData */
|
||||
fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData));
|
||||
fpextra = palloc0_object(PgFdwPathExtraData);
|
||||
fpextra->target = root->upper_targets[UPPERREL_ORDERED];
|
||||
fpextra->has_final_sort = true;
|
||||
|
||||
@@ -7125,7 +7125,7 @@ add_foreign_final_paths(PlannerInfo *root, RelOptInfo *input_rel,
|
||||
fpinfo->pushdown_safe = true;
|
||||
|
||||
/* Construct PgFdwPathExtraData */
|
||||
fpextra = (PgFdwPathExtraData *) palloc0(sizeof(PgFdwPathExtraData));
|
||||
fpextra = palloc0_object(PgFdwPathExtraData);
|
||||
fpextra->target = root->upper_targets[UPPERREL_FINAL];
|
||||
fpextra->has_final_sort = has_final_sort;
|
||||
fpextra->has_limit = extra->limit_needed;
|
||||
|
||||
Reference in New Issue
Block a user