Skip to content

Commit 33a33f0

Browse files
committed
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
1 parent faf3750 commit 33a33f0

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ jsonPathToCstring(StringInfo out, JsonPath *in, int estimated_len)
221221
enlargeStringInfo(out, estimated_len);
222222

223223
if (!(in->header & JSONPATH_LAX))
224-
appendBinaryStringInfo(out, "strict ", 7);
224+
appendStringInfoString(out, "strict ");
225225

226226
jspInit(&v, in);
227227
printJsonPathItem(out, &v, false, true);
@@ -542,9 +542,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
542542
break;
543543
case jpiBool:
544544
if (jspGetBool(v))
545-
appendBinaryStringInfo(buf, "true", 4);
545+
appendStringInfoString(buf, "true");
546546
else
547-
appendBinaryStringInfo(buf, "false", 5);
547+
appendStringInfoString(buf, "false");
548548
break;
549549
case jpiAnd:
550550
case jpiOr:
@@ -585,13 +585,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
585585
operationPriority(elem.type) <=
586586
operationPriority(v->type));
587587

588-
appendBinaryStringInfo(buf, " like_regex ", 12);
588+
appendStringInfoString(buf, " like_regex ");
589589

590590
escape_json(buf, v->content.like_regex.pattern);
591591

592592
if (v->content.like_regex.flags)
593593
{
594-
appendBinaryStringInfo(buf, " flag \"", 7);
594+
appendStringInfoString(buf, " flag \"");
595595

596596
if (v->content.like_regex.flags & JSP_REGEX_ICASE)
597597
appendStringInfoChar(buf, 'i');
@@ -623,13 +623,13 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
623623
appendStringInfoChar(buf, ')');
624624
break;
625625
case jpiFilter:
626-
appendBinaryStringInfo(buf, "?(", 2);
626+
appendStringInfoString(buf, "?(");
627627
jspGetArg(v, &elem);
628628
printJsonPathItem(buf, &elem, false, false);
629629
appendStringInfoChar(buf, ')');
630630
break;
631631
case jpiNot:
632-
appendBinaryStringInfo(buf, "!(", 2);
632+
appendStringInfoString(buf, "!(");
633633
jspGetArg(v, &elem);
634634
printJsonPathItem(buf, &elem, false, false);
635635
appendStringInfoChar(buf, ')');
@@ -638,10 +638,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
638638
appendStringInfoChar(buf, '(');
639639
jspGetArg(v, &elem);
640640
printJsonPathItem(buf, &elem, false, false);
641-
appendBinaryStringInfo(buf, ") is unknown", 12);
641+
appendStringInfoString(buf, ") is unknown");
642642
break;
643643
case jpiExists:
644-
appendBinaryStringInfo(buf, "exists (", 8);
644+
appendStringInfoString(buf, "exists (");
645645
jspGetArg(v, &elem);
646646
printJsonPathItem(buf, &elem, false, false);
647647
appendStringInfoChar(buf, ')');
@@ -655,10 +655,10 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
655655
appendStringInfoChar(buf, '$');
656656
break;
657657
case jpiLast:
658-
appendBinaryStringInfo(buf, "last", 4);
658+
appendStringInfoString(buf, "last");
659659
break;
660660
case jpiAnyArray:
661-
appendBinaryStringInfo(buf, "[*]", 3);
661+
appendStringInfoString(buf, "[*]");
662662
break;
663663
case jpiAnyKey:
664664
if (inKey)
@@ -680,7 +680,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
680680

681681
if (range)
682682
{
683-
appendBinaryStringInfo(buf, " to ", 4);
683+
appendStringInfoString(buf, " to ");
684684
printJsonPathItem(buf, &to, false, false);
685685
}
686686
}
@@ -692,7 +692,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
692692

693693
if (v->content.anybounds.first == 0 &&
694694
v->content.anybounds.last == PG_UINT32_MAX)
695-
appendBinaryStringInfo(buf, "**", 2);
695+
appendStringInfoString(buf, "**");
696696
else if (v->content.anybounds.first == v->content.anybounds.last)
697697
{
698698
if (v->content.anybounds.first == PG_UINT32_MAX)
@@ -713,25 +713,25 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
713713
v->content.anybounds.last);
714714
break;
715715
case jpiType:
716-
appendBinaryStringInfo(buf, ".type()", 7);
716+
appendStringInfoString(buf, ".type()");
717717
break;
718718
case jpiSize:
719-
appendBinaryStringInfo(buf, ".size()", 7);
719+
appendStringInfoString(buf, ".size()");
720720
break;
721721
case jpiAbs:
722-
appendBinaryStringInfo(buf, ".abs()", 6);
722+
appendStringInfoString(buf, ".abs()");
723723
break;
724724
case jpiFloor:
725-
appendBinaryStringInfo(buf, ".floor()", 8);
725+
appendStringInfoString(buf, ".floor()");
726726
break;
727727
case jpiCeiling:
728-
appendBinaryStringInfo(buf, ".ceiling()", 10);
728+
appendStringInfoString(buf, ".ceiling()");
729729
break;
730730
case jpiDouble:
731-
appendBinaryStringInfo(buf, ".double()", 9);
731+
appendStringInfoString(buf, ".double()");
732732
break;
733733
case jpiDatetime:
734-
appendBinaryStringInfo(buf, ".datetime(", 10);
734+
appendStringInfoString(buf, ".datetime(");
735735
if (v->content.arg)
736736
{
737737
jspGetArg(v, &elem);
@@ -740,7 +740,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
740740
appendStringInfoChar(buf, ')');
741741
break;
742742
case jpiKeyValue:
743-
appendBinaryStringInfo(buf, ".keyvalue()", 11);
743+
appendStringInfoString(buf, ".keyvalue()");
744744
break;
745745
default:
746746
elog(ERROR, "unrecognized jsonpath item type: %d", v->type);

0 commit comments

Comments
 (0)