aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2019-07-23 00:14:11 +1200
committerDavid Rowley <drowley@postgresql.org>2019-07-23 00:14:11 +1200
commit1e6a759838f7c104f3cd1fe6981a98780da4131b (patch)
tree47047d8991d0918b531fe71f38b637dc086c9ffa
parent19781729f789f3c6b2540e02b96f8aa500460322 (diff)
downloadpostgresql-1e6a759838f7c104f3cd1fe6981a98780da4131b.tar.gz
postgresql-1e6a759838f7c104f3cd1fe6981a98780da4131b.zip
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
-rw-r--r--contrib/postgres_fdw/deparse.c4
-rw-r--r--src/backend/executor/execMain.c4
-rw-r--r--src/backend/executor/execPartition.c2
-rw-r--r--src/backend/storage/lmgr/deadlock.c2
-rw-r--r--src/backend/utils/adt/ri_triggers.c4
-rw-r--r--src/backend/utils/adt/ruleutils.c10
-rw-r--r--src/backend/utils/adt/xml.c12
7 files changed, 20 insertions, 18 deletions
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c
index 548ae66119b..19f928ec598 100644
--- a/contrib/postgres_fdw/deparse.c
+++ b/contrib/postgres_fdw/deparse.c
@@ -1531,7 +1531,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
{
Assert(fpinfo->jointype == JOIN_INNER);
Assert(fpinfo->joinclauses == NIL);
- appendStringInfoString(buf, join_sql_o.data);
+ appendBinaryStringInfo(buf, join_sql_o.data, join_sql_o.len);
return;
}
}
@@ -1552,7 +1552,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
{
Assert(fpinfo->jointype == JOIN_INNER);
Assert(fpinfo->joinclauses == NIL);
- appendStringInfoString(buf, join_sql_i.data);
+ appendBinaryStringInfo(buf, join_sql_i.data, join_sql_i.len);
return;
}
}
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 29e2681484c..dbd7dd9bcd4 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -2290,7 +2290,7 @@ ExecBuildSlotValueDescription(Oid reloid,
/* truncate if needed */
vallen = strlen(val);
if (vallen <= maxfieldlen)
- appendStringInfoString(&buf, val);
+ appendBinaryStringInfo(&buf, val, vallen);
else
{
vallen = pg_mbcliplen(val, vallen, maxfieldlen);
@@ -2309,7 +2309,7 @@ ExecBuildSlotValueDescription(Oid reloid,
if (!table_perm)
{
appendStringInfoString(&collist, ") = ");
- appendStringInfoString(&collist, buf.data);
+ appendBinaryStringInfo(&collist, buf.data, buf.len);
return collist.data;
}
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index f49a48adb68..729dc396a94 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -1406,7 +1406,7 @@ ExecBuildSlotPartitionKeyDescription(Relation rel,
/* truncate if needed */
vallen = strlen(val);
if (vallen <= maxfieldlen)
- appendStringInfoString(&buf, val);
+ appendBinaryStringInfo(&buf, val, vallen);
else
{
vallen = pg_mbcliplen(val, vallen, maxfieldlen);
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c
index 9abc9d778f6..990d48377d8 100644
--- a/src/backend/storage/lmgr/deadlock.c
+++ b/src/backend/storage/lmgr/deadlock.c
@@ -1115,7 +1115,7 @@ DeadLockReport(void)
}
/* Duplicate all the above for the server ... */
- appendStringInfoString(&logbuf, clientbuf.data);
+ appendBinaryStringInfo(&logbuf, clientbuf.data, clientbuf.len);
/* ... and add info about query strings */
for (i = 0; i < nDeadlockDetails; i++)
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c
index 44a6eef5bbf..8c895459c37 100644
--- a/src/backend/utils/adt/ri_triggers.c
+++ b/src/backend/utils/adt/ri_triggers.c
@@ -927,7 +927,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
queryoids[i] = pk_type;
queryoids[j] = pk_type;
}
- appendStringInfoString(&querybuf, qualbuf.data);
+ appendBinaryStringInfo(&querybuf, qualbuf.data, qualbuf.len);
/* Prepare and save the plan */
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys * 2, queryoids,
@@ -1106,7 +1106,7 @@ ri_set(TriggerData *trigdata, bool is_set_null)
qualsep = "AND";
queryoids[i] = pk_type;
}
- appendStringInfoString(&querybuf, qualbuf.data);
+ appendBinaryStringInfo(&querybuf, qualbuf.data, qualbuf.len);
/* Prepare and save the plan */
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids,
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 4ca0ed2bbbd..0c58f1f1096 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2804,9 +2804,9 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
appendStringInfoChar(&dq, 'x');
appendStringInfoChar(&dq, '$');
- appendStringInfoString(&buf, dq.data);
+ appendBinaryStringInfo(&buf, dq.data, dq.len);
appendStringInfoString(&buf, prosrc);
- appendStringInfoString(&buf, dq.data);
+ appendBinaryStringInfo(&buf, dq.data, dq.len);
appendStringInfoChar(&buf, '\n');
@@ -2930,7 +2930,7 @@ print_function_rettype(StringInfo buf, HeapTuple proctup)
appendStringInfoString(&rbuf, format_type_be(proc->prorettype));
}
- appendStringInfoString(buf, rbuf.data);
+ appendBinaryStringInfo(buf, rbuf.data, rbuf.len);
}
/*
@@ -5682,7 +5682,7 @@ get_target_list(List *targetList, deparse_context *context,
}
/* Add the new field */
- appendStringInfoString(buf, targetbuf.data);
+ appendBinaryStringInfo(buf, targetbuf.data, targetbuf.len);
}
/* clean up */
@@ -9987,7 +9987,7 @@ get_from_clause(Query *query, const char *prefix, deparse_context *context)
}
/* Add the new item */
- appendStringInfoString(buf, itembuf.data);
+ appendBinaryStringInfo(buf, itembuf.data, itembuf.len);
/* clean up */
pfree(itembuf.data);
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');
}