From bcf1842349fb476852c6d3e7cea41b7244dea6c0 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Tue, 16 Jul 2024 15:55:54 +0300
Subject: [PATCH v1 3/3] Rearrange the order of functions in pgformat.{c,h}

Place functions that send protocol messages of given PgMsg type closer
to each other. This makes no difference for the compiler but makes the code
easier to read for humans.

Aleksander Alekseev, reviewed by TODO FIXME
Discussion: TODO FIXME
---
 src/backend/libpq/pqformat.c | 70 ++++++++++++++++++------------------
 src/include/libpq/pqformat.h |  6 ++--
 2 files changed, 37 insertions(+), 39 deletions(-)

diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c
index fca295b8f7..5f4562fc45 100644
--- a/src/backend/libpq/pqformat.c
+++ b/src/backend/libpq/pqformat.c
@@ -79,6 +79,40 @@
 #include "port/pg_bswap.h"
 #include "varatt.h"
 
+/* --------------------------------
+ *		pq_puttextmessage - generate a character set-converted message in one step
+ *
+ *		This is the same as the pqcomm.c routine pq_putmessage, except that
+ *		the message body is a null-terminated string to which encoding
+ *		conversion applies.
+ * --------------------------------
+ */
+void
+pq_puttextmessage(PgMsg msgtype, const char *str)
+{
+	int			slen = strlen(str);
+	char	   *p;
+
+	p = pg_server_to_client(str, slen);
+	if (p != str)				/* actual conversion has been done? */
+	{
+		(void) pq_putmessage(msgtype, p, strlen(p) + 1);
+		pfree(p);
+		return;
+	}
+	(void) pq_putmessage(msgtype, str, slen + 1);
+}
+
+
+/* --------------------------------
+ *		pq_putemptymessage - convenience routine for message with empty body
+ * --------------------------------
+ */
+void
+pq_putemptymessage(PgMsg msgtype)
+{
+	(void) pq_putmessage(msgtype, NULL, 0);
+}
 
 /* --------------------------------
  *		pq_beginmessage		- initialize for sending a message
@@ -355,42 +389,6 @@ pq_endtypsend(StringInfo buf)
 }
 
 
-/* --------------------------------
- *		pq_puttextmessage - generate a character set-converted message in one step
- *
- *		This is the same as the pqcomm.c routine pq_putmessage, except that
- *		the message body is a null-terminated string to which encoding
- *		conversion applies.
- * --------------------------------
- */
-void
-pq_puttextmessage(PgMsg msgtype, const char *str)
-{
-	int			slen = strlen(str);
-	char	   *p;
-
-	p = pg_server_to_client(str, slen);
-	if (p != str)				/* actual conversion has been done? */
-	{
-		(void) pq_putmessage(msgtype, p, strlen(p) + 1);
-		pfree(p);
-		return;
-	}
-	(void) pq_putmessage(msgtype, str, slen + 1);
-}
-
-
-/* --------------------------------
- *		pq_putemptymessage - convenience routine for message with empty body
- * --------------------------------
- */
-void
-pq_putemptymessage(PgMsg msgtype)
-{
-	(void) pq_putmessage(msgtype, NULL, 0);
-}
-
-
 /* --------------------------------
  *		pq_getmsgbyte	- get a raw byte from a message buffer
  * --------------------------------
diff --git a/src/include/libpq/pqformat.h b/src/include/libpq/pqformat.h
index dda004943c..b8f29cee2f 100644
--- a/src/include/libpq/pqformat.h
+++ b/src/include/libpq/pqformat.h
@@ -18,6 +18,9 @@
 #include "mb/pg_wchar.h"
 #include "port/pg_bswap.h"
 
+extern void pq_puttextmessage(PgMsg msgtype, const char *str);
+extern void pq_putemptymessage(PgMsg msgtype);
+
 extern void pq_beginmessage(StringInfo buf, PgMsg msgtype);
 extern void pq_beginmessage_reuse(StringInfo buf, PgMsg msgtype);
 extern void pq_endmessage(StringInfo buf);
@@ -192,9 +195,6 @@ pq_sendint(StringInfo buf, uint32 i, int b)
 extern void pq_begintypsend(StringInfo buf);
 extern bytea *pq_endtypsend(StringInfo buf);
 
-extern void pq_puttextmessage(PgMsg msgtype, const char *str);
-extern void pq_putemptymessage(PgMsg msgtype);
-
 extern int	pq_getmsgbyte(StringInfo msg);
 extern unsigned int pq_getmsgint(StringInfo msg, int b);
 extern int64 pq_getmsgint64(StringInfo msg);
-- 
2.45.2

