From 9f56571b24f72de928ddf8e05eabb1748d20f8b2 Mon Sep 17 00:00:00 2001
From: "dgrowley@gmail.com" <dgrowley@gmail.com>
Date: Sun, 28 Apr 2019 14:15:05 +1200
Subject: [PATCH 3/4] Inline appendStringInfoString

Making this inline gives the compiler flexibility to optimize away strlen
calls when appendStringInfoString is called with a string constant, to which
it seemingly is, most of the time.
---
 src/backend/lib/stringinfo.c | 12 ------------
 src/bin/pg_waldump/compat.c  |  2 +-
 src/include/lib/stringinfo.h | 25 +++++++++++++++----------
 3 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c
index 99c83c1549..74ba478c0d 100644
--- a/src/backend/lib/stringinfo.c
+++ b/src/backend/lib/stringinfo.c
@@ -153,18 +153,6 @@ appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
 	return (int) nprinted;
 }
 
-/*
- * appendStringInfoString
- *
- * Append a null-terminated string to str.
- * Like appendStringInfo(str, "%s", s) but faster.
- */
-void
-appendStringInfoString(StringInfo str, const char *s)
-{
-	appendBinaryStringInfo(str, s, strlen(s));
-}
-
 /*
  * appendStringInfoChar
  *
diff --git a/src/bin/pg_waldump/compat.c b/src/bin/pg_waldump/compat.c
index 0e0dca7d1a..a22a0e88a7 100644
--- a/src/bin/pg_waldump/compat.c
+++ b/src/bin/pg_waldump/compat.c
@@ -79,7 +79,7 @@ appendStringInfo(StringInfo str, const char *fmt,...)
 }
 
 void
-appendStringInfoString(StringInfo str, const char *string)
+appendBinaryStringInfo(StringInfo str, const char *string, int datalen)
 {
 	appendStringInfo(str, "%s", string);
 }
diff --git a/src/include/lib/stringinfo.h b/src/include/lib/stringinfo.h
index c4842778c5..2e5aedb1a3 100644
--- a/src/include/lib/stringinfo.h
+++ b/src/include/lib/stringinfo.h
@@ -105,12 +105,25 @@ extern void appendStringInfo(StringInfo str, const char *fmt,...) pg_attribute_p
  */
 extern int	appendStringInfoVA(StringInfo str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
 
+/*------------------------
+ * appendBinaryStringInfo
+ * Append arbitrary binary data to a StringInfo, allocating more space
+ * if necessary.
+ */
+extern void appendBinaryStringInfo(StringInfo str, const char *data,
+								   int datalen);
+
 /*------------------------
  * appendStringInfoString
  * Append a null-terminated string to str.
- * Like appendStringInfo(str, "%s", s) but faster.
+ * Like appendStringInfo(str, "%s", s) but faster and inlined to allow
+ * compilers to optimize out the strlen call when used with string constants.
  */
-extern void appendStringInfoString(StringInfo str, const char *s);
+static inline void
+appendStringInfoString(StringInfo str, const char *s)
+{
+	appendBinaryStringInfo(str, s, strlen(s));
+}
 
 /*------------------------
  * appendStringInfoChar
@@ -135,14 +148,6 @@ extern void appendStringInfoChar(StringInfo str, char ch);
  */
 extern void appendStringInfoSpaces(StringInfo str, int count);
 
-/*------------------------
- * appendBinaryStringInfo
- * Append arbitrary binary data to a StringInfo, allocating more space
- * if necessary.
- */
-extern void appendBinaryStringInfo(StringInfo str,
-								   const char *data, int datalen);
-
 /*------------------------
  * appendBinaryStringInfoNT
  * Append arbitrary binary data to a StringInfo, allocating more space
-- 
2.20.1

