1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +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

@ -668,7 +668,7 @@ xpath_table(PG_FUNCTION_ARGS)
* document */
int had_values; /* To determine end of nodeset results */
StringInfo querysql;
StringInfoData query_buf;
/* We only have a valid tuple description in table function mode */
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
@ -746,11 +746,10 @@ xpath_table(PG_FUNCTION_ARGS)
} while ((pos != NULL) && (numpaths < (ret_tupdesc->natts - 1)));
/* Now build query */
querysql = makeStringInfo();
initStringInfo(&query_buf);
/* Build initial sql statement */
appendStringInfo(querysql, "SELECT %s, %s FROM %s WHERE %s",
appendStringInfo(&query_buf, "SELECT %s, %s FROM %s WHERE %s",
pkeyfield,
xmlfield,
relname,
@ -761,8 +760,8 @@ xpath_table(PG_FUNCTION_ARGS)
if ((ret = SPI_connect()) < 0)
elog(ERROR, "xpath_table: SPI_connect returned %d", ret);
if ((ret = SPI_exec(querysql->data, 0)) != SPI_OK_SELECT)
elog(ERROR, "xpath_table: SPI execution failed for query %s", querysql->data);
if ((ret = SPI_exec(query_buf.data, 0)) != SPI_OK_SELECT)
elog(ERROR, "xpath_table: SPI execution failed for query %s", query_buf.data);
proc = SPI_processed;
/* elog(DEBUG1,"xpath_table: SPI returned %d rows",proc); */