Attached is a patch that replaces a bunch of places where StringInfos
are unnecessarily allocated on the heap rather than the stack. That is,
this is sub-optimal:
{
StringInfo str;
str = makeStringInfo();
/* use str */
pfree(str->data);
pfree(str);
}
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:
{
StringInfoData str;
initStringInfo(&str);
/* use str */
pfree(str.data);
}
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.
A bunch of places in the tree (mostly contrib/) were using
makeStringInfo() when there was no need to do so -- this patch replaces
that with a stack-allocated StringInfoData and initStringInfo(). 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.
Barring any objections I'll apply this tomorrow.
-Neil