v2-0001-Use-appendStringInfoString-instead-of-appendBinar.patch

text/plain

Filename: v2-0001-Use-appendStringInfoString-instead-of-appendBinar.patch
Type: text/plain
Part: 0
Message: Re: appendBinaryStringInfo stuff

Patch

Format: format-patch
Series: patch v2-0001
Subject: Use appendStringInfoString instead of appendBinaryStringInfo where possible
File+
src/backend/utils/adt/jsonpath.c 21 21
From 319c206bec80d326808a211f9edd50346edbeb8c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 19 Dec 2022 07:01:27 +0100
Subject: [PATCH v2 1/2] Use appendStringInfoString instead of
 appendBinaryStringInfo where possible

For the jsonpath output, we don't need to squeeze out every bit of
performance, so instead use a more robust coding style.  There are
similar calls in jsonb.c, which we leave alone here since there is
indeed a performance impact for bulk exports.

Discussion: https://www.postgresql.org/message-id/flat/a0086cfc-ff0f-2827-20fe-52b591d2666c%40enterprisedb.com
---
 src/backend/utils/adt/jsonpath.c | 42 ++++++++++++++++----------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/backend/utils/adt/jsonpath.c b/src/backend/utils/adt/jsonpath.c
index 91af030095..a39eab9c20 100644
--- a/src/backend/utils/adt/jsonpath.c
+++ b/src/backend/utils/adt/jsonpath.c
@@ -213,7 +213,7 @@ jsonPathToCstring(StringInfo out, JsonPath *in, int estimated_len)
 	enlargeStringInfo(out, estimated_len);
 
 	if (!(in->header & JSONPATH_LAX))
-		appendBinaryStringInfo(out, "strict ", 7);
+		appendStringInfoString(out, "strict ");
 
 	jspInit(&v, in);
 	printJsonPathItem(out, &v, false, true);
@@ -510,9 +510,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 			break;
 		case jpiBool:
 			if (jspGetBool(v))
-				appendBinaryStringInfo(buf, "true", 4);
+				appendStringInfoString(buf, "true");
 			else
-				appendBinaryStringInfo(buf, "false", 5);
+				appendStringInfoString(buf, "false");
 			break;
 		case jpiAnd:
 		case jpiOr:
@@ -553,13 +553,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 							  operationPriority(elem.type) <=
 							  operationPriority(v->type));
 
-			appendBinaryStringInfo(buf, " like_regex ", 12);
+			appendStringInfoString(buf, " like_regex ");
 
 			escape_json(buf, v->content.like_regex.pattern);
 
 			if (v->content.like_regex.flags)
 			{
-				appendBinaryStringInfo(buf, " flag \"", 7);
+				appendStringInfoString(buf, " flag \"");
 
 				if (v->content.like_regex.flags & JSP_REGEX_ICASE)
 					appendStringInfoChar(buf, 'i');
@@ -591,13 +591,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 				appendStringInfoChar(buf, ')');
 			break;
 		case jpiFilter:
-			appendBinaryStringInfo(buf, "?(", 2);
+			appendStringInfoString(buf, "?(");
 			jspGetArg(v, &elem);
 			printJsonPathItem(buf, &elem, false, false);
 			appendStringInfoChar(buf, ')');
 			break;
 		case jpiNot:
-			appendBinaryStringInfo(buf, "!(", 2);
+			appendStringInfoString(buf, "!(");
 			jspGetArg(v, &elem);
 			printJsonPathItem(buf, &elem, false, false);
 			appendStringInfoChar(buf, ')');
@@ -606,10 +606,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 			appendStringInfoChar(buf, '(');
 			jspGetArg(v, &elem);
 			printJsonPathItem(buf, &elem, false, false);
-			appendBinaryStringInfo(buf, ") is unknown", 12);
+			appendStringInfoString(buf, ") is unknown");
 			break;
 		case jpiExists:
-			appendBinaryStringInfo(buf, "exists (", 8);
+			appendStringInfoString(buf, "exists (");
 			jspGetArg(v, &elem);
 			printJsonPathItem(buf, &elem, false, false);
 			appendStringInfoChar(buf, ')');
@@ -623,10 +623,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 			appendStringInfoChar(buf, '$');
 			break;
 		case jpiLast:
-			appendBinaryStringInfo(buf, "last", 4);
+			appendStringInfoString(buf, "last");
 			break;
 		case jpiAnyArray:
-			appendBinaryStringInfo(buf, "[*]", 3);
+			appendStringInfoString(buf, "[*]");
 			break;
 		case jpiAnyKey:
 			if (inKey)
@@ -648,7 +648,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 
 				if (range)
 				{
-					appendBinaryStringInfo(buf, " to ", 4);
+					appendStringInfoString(buf, " to ");
 					printJsonPathItem(buf, &to, false, false);
 				}
 			}
@@ -660,7 +660,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 
 			if (v->content.anybounds.first == 0 &&
 				v->content.anybounds.last == PG_UINT32_MAX)
-				appendBinaryStringInfo(buf, "**", 2);
+				appendStringInfoString(buf, "**");
 			else if (v->content.anybounds.first == v->content.anybounds.last)
 			{
 				if (v->content.anybounds.first == PG_UINT32_MAX)
@@ -681,25 +681,25 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 								 v->content.anybounds.last);
 			break;
 		case jpiType:
-			appendBinaryStringInfo(buf, ".type()", 7);
+			appendStringInfoString(buf, ".type()");
 			break;
 		case jpiSize:
-			appendBinaryStringInfo(buf, ".size()", 7);
+			appendStringInfoString(buf, ".size()");
 			break;
 		case jpiAbs:
-			appendBinaryStringInfo(buf, ".abs()", 6);
+			appendStringInfoString(buf, ".abs()");
 			break;
 		case jpiFloor:
-			appendBinaryStringInfo(buf, ".floor()", 8);
+			appendStringInfoString(buf, ".floor()");
 			break;
 		case jpiCeiling:
-			appendBinaryStringInfo(buf, ".ceiling()", 10);
+			appendStringInfoString(buf, ".ceiling()");
 			break;
 		case jpiDouble:
-			appendBinaryStringInfo(buf, ".double()", 9);
+			appendStringInfoString(buf, ".double()");
 			break;
 		case jpiDatetime:
-			appendBinaryStringInfo(buf, ".datetime(", 10);
+			appendStringInfoString(buf, ".datetime(");
 			if (v->content.arg)
 			{
 				jspGetArg(v, &elem);
@@ -708,7 +708,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
 			appendStringInfoChar(buf, ')');
 			break;
 		case jpiKeyValue:
-			appendBinaryStringInfo(buf, ".keyvalue()", 11);
+			appendStringInfoString(buf, ".keyvalue()");
 			break;
 		default:
 			elog(ERROR, "unrecognized jsonpath item type: %d", v->type);

base-commit: f4f2f2b84a0bbf9edbfc4a8684040a941cd6d085
-- 
2.39.0