From 9544edaece51420e24520df13a651d56e3bdf150 Mon Sep 17 00:00:00 2001
From: "dgrowley@gmail.com" <dgrowley@gmail.com>
Date: Sun, 28 Apr 2019 20:56:58 +1200
Subject: [PATCH 4/4] Add appendStringInfoStringInfo to append one StringInfo
 to another

This could be done previously with appendStringInfoString(t, s.data) or with
appendBinaryStringInfo(t, s.data, s.len), however the new function is faster
than the former and neater than the latter.
---
 contrib/postgres_fdw/deparse.c      |  4 ++--
 src/backend/executor/execMain.c     |  2 +-
 src/backend/storage/lmgr/deadlock.c |  2 +-
 src/backend/utils/adt/ri_triggers.c |  4 ++--
 src/backend/utils/adt/ruleutils.c   | 10 +++++-----
 src/backend/utils/adt/xml.c         | 10 +++++-----
 src/include/lib/stringinfo.h        | 10 ++++++++++
 7 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c
index b951b11592..7724dbf8a7 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);
+				appendStringInfoStringInfo(buf, &join_sql_o);
 				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);
+				appendStringInfoStringInfo(buf, &join_sql_i);
 				return;
 			}
 		}
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 8c8528b134..49f66fb021 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -2309,7 +2309,7 @@ ExecBuildSlotValueDescription(Oid reloid,
 	if (!table_perm)
 	{
 		appendStringInfoString(&collist, ") = ");
-		appendStringInfoString(&collist, buf.data);
+		appendStringInfoStringInfo(&collist, &buf);
 
 		return collist.data;
 	}
diff --git a/src/backend/storage/lmgr/deadlock.c b/src/backend/storage/lmgr/deadlock.c
index 9abc9d778f..14a47b9e66 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);
+	appendStringInfoStringInfo(&logbuf, &clientbuf);
 
 	/* ... 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 44a6eef5bb..5b4872db09 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);
+		appendStringInfoStringInfo(&querybuf, &qualbuf);
 
 		/* 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);
+		appendStringInfoStringInfo(&querybuf, &qualbuf);
 
 		/* 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 421b622b5e..8ee50494e1 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);
+	appendStringInfoStringInfo(&buf, &dq);
 	appendStringInfoString(&buf, prosrc);
-	appendStringInfoString(&buf, dq.data);
+	appendStringInfoStringInfo(&buf, &dq);
 
 	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);
+	appendStringInfoStringInfo(buf, &rbuf);
 }
 
 /*
@@ -5684,7 +5684,7 @@ get_target_list(List *targetList, deparse_context *context,
 		}
 
 		/* Add the new field */
-		appendStringInfoString(buf, targetbuf.data);
+		appendStringInfoStringInfo(buf, &targetbuf);
 	}
 
 	/* clean up */
@@ -9989,7 +9989,7 @@ get_from_clause(Query *query, const char *prefix, deparse_context *context)
 			}
 
 			/* Add the new item */
-			appendStringInfoString(buf, itembuf.data);
+			appendStringInfoStringInfo(buf, &itembuf);
 
 			/* clean up */
 			pfree(itembuf.data);
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index d43c3055f3..2a3f5403cf 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);
+		appendStringInfoStringInfo(&buf2, &buf);
 		buf = buf2;
 	}
 
@@ -1879,7 +1879,7 @@ xml_errorHandler(void *data, xmlErrorPtr error)
 	if (xmlerrcxt->strictness == PG_XML_STRICTNESS_LEGACY)
 	{
 		appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
-		appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data);
+		appendStringInfoStringInfo(&xmlerrcxt->err_buf, errorBuf);
 
 		pfree(errorBuf->data);
 		pfree(errorBuf);
@@ -1897,7 +1897,7 @@ xml_errorHandler(void *data, xmlErrorPtr error)
 	if (level >= XML_ERR_ERROR)
 	{
 		appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
-		appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data);
+		appendStringInfoStringInfo(&xmlerrcxt->err_buf, errorBuf);
 
 		xmlerrcxt->err_occurred = true;
 	}
@@ -2874,7 +2874,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);
+		appendStringInfoStringInfo(result, subres);
 		appendStringInfoChar(result, '\n');
 	}
 
@@ -3049,7 +3049,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);
+		appendStringInfoStringInfo(result, subres);
 		appendStringInfoChar(result, '\n');
 	}
 
diff --git a/src/include/lib/stringinfo.h b/src/include/lib/stringinfo.h
index 2e5aedb1a3..3fad5c5fc1 100644
--- a/src/include/lib/stringinfo.h
+++ b/src/include/lib/stringinfo.h
@@ -125,6 +125,16 @@ appendStringInfoString(StringInfo str, const char *s)
 	appendBinaryStringInfo(str, s, strlen(s));
 }
 
+/*------------------------
+ * appendStringInfoStringInfo
+ * Append the 'src' StringInfo to 'str'.
+ */
+static inline void
+appendStringInfoStringInfo(StringInfo str, StringInfo src)
+{
+	appendBinaryStringInfo(str, src->data, src->len);
+}
+
 /*------------------------
  * appendStringInfoChar
  * Append a single byte to str.
-- 
2.20.1

