aboutsummaryrefslogtreecommitdiff
path: root/contrib/xml2/xpath.c
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2006-03-01 06:51:01 +0000
committerNeil Conway <neilc@samurai.com>2006-03-01 06:51:01 +0000
commit0d9742f99aa0ba6b96d0729dd2cb2634a29d0be9 (patch)
tree3936c2893718f65ff538c359bd75bdcf14d9725e /contrib/xml2/xpath.c
parent8e5a10d46c38976e40504456a5978caa53b77b3c (diff)
downloadpostgresql-0d9742f99aa0ba6b96d0729dd2cb2634a29d0be9.tar.gz
postgresql-0d9742f99aa0ba6b96d0729dd2cb2634a29d0be9.zip
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.
Diffstat (limited to 'contrib/xml2/xpath.c')
-rw-r--r--contrib/xml2/xpath.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index 662731b5c04..3dfcdadf96b 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -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); */