mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Use stack allocated StringInfoDatas, where possible
Various places that were using StringInfo but didn't need that StringInfo to exist beyond the scope of the function were using makeStringInfo(), which allocates both a StringInfoData and the buffer it uses as two separate allocations. It's more efficient for these cases to use a StringInfoData on the stack and initialize it with initStringInfo(), which only allocates the string buffer. This also simplifies the cleanup, in a few cases. Author: Mats Kindahl <mats.kindahl@gmail.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/4379aac8-26f1-42f2-a356-ff0e886228d3@gmail.com
This commit is contained in:
@@ -2841,7 +2841,7 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
*/
|
||||
if (list_length(fdw_private) > FdwScanPrivateRelations)
|
||||
{
|
||||
StringInfo relations;
|
||||
StringInfoData relations;
|
||||
char *rawrelations;
|
||||
char *ptr;
|
||||
int minrti,
|
||||
@@ -2875,7 +2875,7 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
rtoffset = bms_next_member(plan->fs_base_relids, -1) - minrti;
|
||||
|
||||
/* Now we can translate the string */
|
||||
relations = makeStringInfo();
|
||||
initStringInfo(&relations);
|
||||
ptr = rawrelations;
|
||||
while (*ptr)
|
||||
{
|
||||
@@ -2897,24 +2897,24 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
|
||||
char *namespace;
|
||||
|
||||
namespace = get_namespace_name_or_temp(get_rel_namespace(rte->relid));
|
||||
appendStringInfo(relations, "%s.%s",
|
||||
appendStringInfo(&relations, "%s.%s",
|
||||
quote_identifier(namespace),
|
||||
quote_identifier(relname));
|
||||
}
|
||||
else
|
||||
appendStringInfoString(relations,
|
||||
appendStringInfoString(&relations,
|
||||
quote_identifier(relname));
|
||||
refname = (char *) list_nth(es->rtable_names, rti - 1);
|
||||
if (refname == NULL)
|
||||
refname = rte->eref->aliasname;
|
||||
if (strcmp(refname, relname) != 0)
|
||||
appendStringInfo(relations, " %s",
|
||||
appendStringInfo(&relations, " %s",
|
||||
quote_identifier(refname));
|
||||
}
|
||||
else
|
||||
appendStringInfoChar(relations, *ptr++);
|
||||
appendStringInfoChar(&relations, *ptr++);
|
||||
}
|
||||
ExplainPropertyText("Relations", relations->data, es);
|
||||
ExplainPropertyText("Relations", relations.data, es);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user