1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Attached is a patch that replaces a bunch of places where StringInfos

are unnecessarily allocated on the heap rather than the stack. If the
StringInfo doesn't outlive the stack frame in which it is created,
there is no need to allocate it on the heap via makeStringInfo() --
stack allocation is faster.  While it's not a big deal unless the
code is in a critical path, I don't see a reason not to save a few
cycles -- using stack allocation is not less readable.

I also cleaned up a bit of code along the way: moved variable
declarations into a more tightly-enclosing scope where possible,
fixed some pointless copying of strings in dblink, etc.
This commit is contained in:
Neil Conway
2006-03-01 06:51:01 +00:00
parent 8e5a10d46c
commit 0d9742f99a
5 changed files with 126 additions and 140 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.144 2006/02/28 04:10:27 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.145 2006/03/01 06:51:01 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@ -232,7 +232,7 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
instr_time starttime;
double totaltime = 0;
ExplainState *es;
StringInfo str;
StringInfoData buf;
int eflags;
INSTR_TIME_SET_CURRENT(starttime);
@ -285,9 +285,8 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
}
}
str = makeStringInfo();
explain_outNode(str, queryDesc->plantree, queryDesc->planstate,
initStringInfo(&buf);
explain_outNode(&buf, queryDesc->plantree, queryDesc->planstate,
NULL, 0, es);
/*
@ -335,18 +334,18 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
if (trig->tgisconstraint &&
(conname = GetConstraintNameForTrigger(trig->tgoid)) != NULL)
{
appendStringInfo(str, "Trigger for constraint %s",
appendStringInfo(&buf, "Trigger for constraint %s",
conname);
pfree(conname);
}
else
appendStringInfo(str, "Trigger %s", trig->tgname);
appendStringInfo(&buf, "Trigger %s", trig->tgname);
if (numrels > 1)
appendStringInfo(str, " on %s",
appendStringInfo(&buf, " on %s",
RelationGetRelationName(rInfo->ri_RelationDesc));
appendStringInfo(str, ": time=%.3f calls=%.0f\n",
appendStringInfo(&buf, ": time=%.3f calls=%.0f\n",
1000.0 * instr->total,
instr->ntuples);
}
@ -370,12 +369,11 @@ ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt,
totaltime += elapsed_time(&starttime);
if (stmt->analyze)
appendStringInfo(str, "Total runtime: %.3f ms\n",
appendStringInfo(&buf, "Total runtime: %.3f ms\n",
1000.0 * totaltime);
do_text_output_multiline(tstate, str->data);
do_text_output_multiline(tstate, buf.data);
pfree(str->data);
pfree(str);
pfree(buf.data);
pfree(es);
}