Skip to content

Commit 110d817

Browse files
committed
Fixup some appendStringInfo and appendPQExpBuffer calls
A number of places were using appendStringInfo() when they could have been using appendStringInfoString() instead. While there's no functionality change there, it's just more efficient to use appendStringInfoString() when no formatting is required. Likewise for some appendStringInfoString() calls which were just appending a single char. We can just use appendStringInfoChar() for that. Additionally, many places were using appendPQExpBuffer() when they could have used appendPQExpBufferStr(). Change those too. Patch by Zhijie Hou, but further searching by me found significantly more places that deserved the same treatment. Author: Zhijie Hou, David Rowley Discussion: https://postgr.es/m/cb172cf4361e4c7ba7167429070979d4@G08CNEXMBPEKD05.g08.fujitsu.local
1 parent 73c381c commit 110d817

File tree

15 files changed

+210
-216
lines changed

15 files changed

+210
-216
lines changed

Diff for: contrib/postgres_fdw/postgres_fdw.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2591,8 +2591,8 @@ postgresExplainForeignScan(ForeignScanState *node, ExplainState *es)
25912591
quote_identifier(relname));
25922592
}
25932593
else
2594-
appendStringInfo(relations, "%s",
2595-
quote_identifier(relname));
2594+
appendStringInfoString(relations,
2595+
quote_identifier(relname));
25962596
refname = (char *) list_nth(es->rtable_names, rti - 1);
25972597
if (refname == NULL)
25982598
refname = rte->eref->aliasname;

Diff for: contrib/test_decoding/test_decoding.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ pg_output_stream_start(LogicalDecodingContext *ctx, TestDecodingData *data, Reor
606606
if (data->include_xids)
607607
appendStringInfo(ctx->out, "opening a streamed block for transaction TXN %u", txn->xid);
608608
else
609-
appendStringInfo(ctx->out, "opening a streamed block for transaction");
609+
appendStringInfoString(ctx->out, "opening a streamed block for transaction");
610610
OutputPluginWrite(ctx, last_write);
611611
}
612612

@@ -623,7 +623,7 @@ pg_decode_stream_stop(LogicalDecodingContext *ctx,
623623
if (data->include_xids)
624624
appendStringInfo(ctx->out, "closing a streamed block for transaction TXN %u", txn->xid);
625625
else
626-
appendStringInfo(ctx->out, "closing a streamed block for transaction");
626+
appendStringInfoString(ctx->out, "closing a streamed block for transaction");
627627
OutputPluginWrite(ctx, true);
628628
}
629629

@@ -641,7 +641,7 @@ pg_decode_stream_abort(LogicalDecodingContext *ctx,
641641
if (data->include_xids)
642642
appendStringInfo(ctx->out, "aborting streamed (sub)transaction TXN %u", txn->xid);
643643
else
644-
appendStringInfo(ctx->out, "aborting streamed (sub)transaction");
644+
appendStringInfoString(ctx->out, "aborting streamed (sub)transaction");
645645
OutputPluginWrite(ctx, true);
646646
}
647647

@@ -660,7 +660,7 @@ pg_decode_stream_commit(LogicalDecodingContext *ctx,
660660
if (data->include_xids)
661661
appendStringInfo(ctx->out, "committing streamed transaction TXN %u", txn->xid);
662662
else
663-
appendStringInfo(ctx->out, "committing streamed transaction");
663+
appendStringInfoString(ctx->out, "committing streamed transaction");
664664

665665
if (data->include_timestamp)
666666
appendStringInfo(ctx->out, " (at %s)",
@@ -693,7 +693,7 @@ pg_decode_stream_change(LogicalDecodingContext *ctx,
693693
if (data->include_xids)
694694
appendStringInfo(ctx->out, "streaming change for TXN %u", txn->xid);
695695
else
696-
appendStringInfo(ctx->out, "streaming change for transaction");
696+
appendStringInfoString(ctx->out, "streaming change for transaction");
697697
OutputPluginWrite(ctx, true);
698698
}
699699

@@ -745,6 +745,6 @@ pg_decode_stream_truncate(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
745745
if (data->include_xids)
746746
appendStringInfo(ctx->out, "streaming truncate for TXN %u", txn->xid);
747747
else
748-
appendStringInfo(ctx->out, "streaming truncate for transaction");
748+
appendStringInfoString(ctx->out, "streaming truncate for transaction");
749749
OutputPluginWrite(ctx, true);
750750
}

Diff for: src/backend/access/rmgrdesc/dbasedesc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dbase_desc(StringInfo buf, XLogReaderState *record)
3737
xl_dbase_drop_rec *xlrec = (xl_dbase_drop_rec *) rec;
3838
int i;
3939

40-
appendStringInfo(buf, "dir");
40+
appendStringInfoString(buf, "dir");
4141
for (i = 0; i < xlrec->ntablespaces; i++)
4242
appendStringInfo(buf, " %u/%u",
4343
xlrec->tablespace_ids[i], xlrec->db_id);

Diff for: src/backend/commands/explain.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -2768,14 +2768,14 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
27682768
groupInfo->groupCount);
27692769
/* plural/singular based on methodNames size */
27702770
if (list_length(methodNames) > 1)
2771-
appendStringInfo(es->str, "s: ");
2771+
appendStringInfoString(es->str, "s: ");
27722772
else
2773-
appendStringInfo(es->str, ": ");
2773+
appendStringInfoString(es->str, ": ");
27742774
foreach(methodCell, methodNames)
27752775
{
2776-
appendStringInfo(es->str, "%s", (char *) methodCell->ptr_value);
2776+
appendStringInfoString(es->str, (char *) methodCell->ptr_value);
27772777
if (foreach_current_index(methodCell) < list_length(methodNames) - 1)
2778-
appendStringInfo(es->str, ", ");
2778+
appendStringInfoString(es->str, ", ");
27792779
}
27802780

27812781
if (groupInfo->maxMemorySpaceUsed > 0)
@@ -2882,11 +2882,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
28822882
if (prefixsortGroupInfo->groupCount > 0)
28832883
{
28842884
if (es->format == EXPLAIN_FORMAT_TEXT)
2885-
appendStringInfo(es->str, "\n");
2885+
appendStringInfoChar(es->str, '\n');
28862886
show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
28872887
}
28882888
if (es->format == EXPLAIN_FORMAT_TEXT)
2889-
appendStringInfo(es->str, "\n");
2889+
appendStringInfoChar(es->str, '\n');
28902890
}
28912891

28922892
if (incrsortstate->shared_info != NULL)
@@ -2925,11 +2925,11 @@ show_incremental_sort_info(IncrementalSortState *incrsortstate,
29252925
if (prefixsortGroupInfo->groupCount > 0)
29262926
{
29272927
if (es->format == EXPLAIN_FORMAT_TEXT)
2928-
appendStringInfo(es->str, "\n");
2928+
appendStringInfoChar(es->str, '\n');
29292929
show_incremental_sort_group_info(prefixsortGroupInfo, "Pre-sorted", true, es);
29302930
}
29312931
if (es->format == EXPLAIN_FORMAT_TEXT)
2932-
appendStringInfo(es->str, "\n");
2932+
appendStringInfoChar(es->str, '\n');
29332933

29342934
if (es->workers_state)
29352935
ExplainCloseWorker(n, es);

Diff for: src/backend/replication/backup_manifest.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
112112
initStringInfo(&buf);
113113
if (manifest->first_file)
114114
{
115-
appendStringInfoString(&buf, "\n");
115+
appendStringInfoChar(&buf, '\n');
116116
manifest->first_file = false;
117117
}
118118
else
@@ -152,7 +152,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
152152
enlargeStringInfo(&buf, 128);
153153
buf.len += pg_strftime(&buf.data[buf.len], 128, "%Y-%m-%d %H:%M:%S %Z",
154154
pg_gmtime(&mtime));
155-
appendStringInfoString(&buf, "\"");
155+
appendStringInfoChar(&buf, '"');
156156

157157
/* Add checksum information. */
158158
if (checksum_ctx->type != CHECKSUM_TYPE_NONE)
@@ -168,7 +168,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, const char *spcoid,
168168
enlargeStringInfo(&buf, 2 * checksumlen);
169169
buf.len += hex_encode((char *) checksumbuf, checksumlen,
170170
&buf.data[buf.len]);
171-
appendStringInfoString(&buf, "\"");
171+
appendStringInfoChar(&buf, '"');
172172
}
173173

174174
/* Close out the object. */

Diff for: src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
427427

428428
if (options->proto.logical.streaming &&
429429
PQserverVersion(conn->streamConn) >= 140000)
430-
appendStringInfo(&cmd, ", streaming 'on'");
430+
appendStringInfoString(&cmd, ", streaming 'on'");
431431

432432
pubnames = options->proto.logical.publication_names;
433433
pubnames_str = stringlist_to_identifierstr(conn->streamConn, pubnames);

Diff for: src/backend/replication/logical/tablesync.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ copy_table(Relation rel)
774774
* For non-tables, we need to do COPY (SELECT ...), but we can't just
775775
* do SELECT * because we need to not copy generated columns.
776776
*/
777-
appendStringInfo(&cmd, "COPY (SELECT ");
777+
appendStringInfoString(&cmd, "COPY (SELECT ");
778778
for (int i = 0; i < lrel.natts; i++)
779779
{
780780
appendStringInfoString(&cmd, quote_identifier(lrel.attnames[i]));

Diff for: src/backend/utils/adt/jsonpath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
660660
else if (v->content.anybounds.first == v->content.anybounds.last)
661661
{
662662
if (v->content.anybounds.first == PG_UINT32_MAX)
663-
appendStringInfo(buf, "**{last}");
663+
appendStringInfoString(buf, "**{last}");
664664
else
665665
appendStringInfo(buf, "**{%u}",
666666
v->content.anybounds.first);

Diff for: src/backend/utils/adt/ri_triggers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ RI_PartitionRemove_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
16631663
appendStringInfo(&querybuf, ") WHERE %s AND (",
16641664
constraintDef);
16651665
else
1666-
appendStringInfo(&querybuf, ") WHERE (");
1666+
appendStringInfoString(&querybuf, ") WHERE (");
16671667

16681668
sep = "";
16691669
for (i = 0; i < riinfo->nkeys; i++)

Diff for: src/backend/utils/adt/ruleutils.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5250,7 +5250,7 @@ get_select_query_def(Query *query, deparse_context *context,
52505250
appendContextKeyword(context, " FETCH FIRST ",
52515251
-PRETTYINDENT_STD, PRETTYINDENT_STD, 0);
52525252
get_rule_expr(query->limitCount, context, false);
5253-
appendStringInfo(buf, " ROWS WITH TIES");
5253+
appendStringInfoString(buf, " ROWS WITH TIES");
52545254
}
52555255
else
52565256
{
@@ -11362,7 +11362,7 @@ get_range_partbound_string(List *bound_datums)
1136211362
memset(&context, 0, sizeof(deparse_context));
1136311363
context.buf = buf;
1136411364

11365-
appendStringInfoString(buf, "(");
11365+
appendStringInfoChar(buf, '(');
1136611366
sep = "";
1136711367
foreach(cell, bound_datums)
1136811368
{

0 commit comments

Comments
 (0)