From 1e6a759838f7c104f3cd1fe6981a98780da4131b Mon Sep 17 00:00:00 2001 From: David Rowley Date: Tue, 23 Jul 2019 00:14:11 +1200 Subject: Use appendBinaryStringInfo in more places where the length is known When we already know the length that we're going to append, then it makes sense to use appendBinaryStringInfo instead of appendStringInfoString so that the append can be performed with a simple memcpy() using a known length rather than having to first perform a strlen() call to obtain the length. Discussion: https://postgr.es/m/CAKJS1f8+FRAM1s5+mAa3isajeEoAaicJ=4e0WzrH3tAusbbiMQ@mail.gmail.com --- src/backend/utils/adt/xml.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/backend/utils/adt/xml.c') diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index d43c3055f3a..5e629d29ea8 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -559,7 +559,7 @@ xmlconcat(List *args) 0, global_standalone); - appendStringInfoString(&buf2, buf.data); + appendBinaryStringInfo(&buf2, buf.data, buf.len); buf = buf2; } @@ -1879,7 +1879,8 @@ xml_errorHandler(void *data, xmlErrorPtr error) if (xmlerrcxt->strictness == PG_XML_STRICTNESS_LEGACY) { appendStringInfoLineSeparator(&xmlerrcxt->err_buf); - appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data); + appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data, + errorBuf->len); pfree(errorBuf->data); pfree(errorBuf); @@ -1897,7 +1898,8 @@ xml_errorHandler(void *data, xmlErrorPtr error) if (level >= XML_ERR_ERROR) { appendStringInfoLineSeparator(&xmlerrcxt->err_buf); - appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data); + appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data, + errorBuf->len); xmlerrcxt->err_occurred = true; } @@ -2874,7 +2876,7 @@ schema_to_xml_internal(Oid nspid, const char *xmlschema, bool nulls, subres = table_to_xml_internal(relid, NULL, nulls, tableforest, targetns, false); - appendStringInfoString(result, subres->data); + appendBinaryStringInfo(result, subres->data, subres->len); appendStringInfoChar(result, '\n'); } @@ -3049,7 +3051,7 @@ database_to_xml_internal(const char *xmlschema, bool nulls, subres = schema_to_xml_internal(nspid, NULL, nulls, tableforest, targetns, false); - appendStringInfoString(result, subres->data); + appendBinaryStringInfo(result, subres->data, subres->len); appendStringInfoChar(result, '\n'); } -- cgit v1.2.3