Tidy-up some appendStringInfo*() usages
authorDavid Rowley <drowley@postgresql.org>
Tue, 3 Oct 2023 04:09:52 +0000 (17:09 +1300)
committerDavid Rowley <drowley@postgresql.org>
Tue, 3 Oct 2023 04:09:52 +0000 (17:09 +1300)
Make a few newish calls to appendStringInfo() which have no special
formatting use appendStringInfoString() instead.  Also, adjust usages of
appendStringInfoString() which only append a string containing a single
character to make use of appendStringInfoChar() instead.

This makes the code marginally faster, but primarily this change is so
we use the StringInfo type as it was intended to be used.

Discussion: https://postgr.es/m/CAApHDvpXKQmL+r=VDNS98upqhr9yGBhv2Jw3GBFFk_wKHcB39A@mail.gmail.com

src/backend/access/rmgrdesc/heapdesc.c
src/backend/access/rmgrdesc/nbtdesc.c
src/backend/access/rmgrdesc/rmgrdesc_utils.c
src/backend/access/transam/xlogbackup.c
src/backend/replication/slot.c
src/backend/utils/adt/ruleutils.c
src/test/regress/pg_regress.c

index d73248abddf27d70dd527959deee0687dfda64b6..f382c0f6236f10876576fa61991920a03b97eaa2 100644 (file)
@@ -47,7 +47,7 @@ infobits_desc(StringInfo buf, uint8 infobits, const char *keyname)
                buf->data[buf->len] = '\0';
        }
 
-       appendStringInfoString(buf, "]");
+       appendStringInfoChar(buf, ']');
 }
 
 static void
@@ -68,7 +68,7 @@ truncate_flags_desc(StringInfo buf, uint8 flags)
                buf->data[buf->len] = '\0';
        }
 
-       appendStringInfoString(buf, "]");
+       appendStringInfoChar(buf, ']');
 }
 
 static void
@@ -88,7 +88,7 @@ plan_elem_desc(StringInfo buf, void *plan, void *data)
 
        *offsets += new_plan->ntuples;
 
-       appendStringInfo(buf, " }");
+       appendStringInfoString(buf, " }");
 }
 
 void
index e4fbaa4d5d5f957ea31dca637ea0c54c3f1a6279..f3d725a274e44c0d6d01110dd5234398be0b2e1f 100644 (file)
@@ -248,5 +248,5 @@ delvacuum_desc(StringInfo buf, char *block_data,
                        ((char *) updates + SizeOfBtreeUpdate +
                         updates->ndeletedtids * sizeof(uint16));
        }
-       appendStringInfoString(buf, "]");
+       appendStringInfoChar(buf, ']');
 }
index 808770524d682500109f4da1b1d41d6e8a3b9751..ef89179bb47c8964531890d3d62a29ec1dc221ee 100644 (file)
@@ -37,7 +37,7 @@ array_desc(StringInfo buf, void *array, size_t elem_size, int count,
                if (i < count - 1)
                        appendStringInfoString(buf, ", ");
        }
-       appendStringInfoString(buf, "]");
+       appendStringInfoChar(buf, ']');
 }
 
 void
index 23461c9d2ca4ef0d0ecc0385f8560d662506c7f5..21d68133ae1065aafd8bfbb2faecdfa765991727 100644 (file)
@@ -58,7 +58,7 @@ build_backup_content(BackupState *state, bool ishistoryfile)
 
        appendStringInfo(result, "CHECKPOINT LOCATION: %X/%X\n",
                                         LSN_FORMAT_ARGS(state->checkpointloc));
-       appendStringInfo(result, "BACKUP METHOD: streamed\n");
+       appendStringInfoString(result, "BACKUP METHOD: streamed\n");
        appendStringInfo(result, "BACKUP FROM: %s\n",
                                         state->started_in_recovery ? "standby" : "primary");
        appendStringInfo(result, "START TIME: %s\n", startstrbuf);
index 3ded3c1473c7e3ddf1502bd00480670ebb7044b0..7e5ec500d8960b9a7d1f14016d2aef41baac975f 100644 (file)
@@ -1282,7 +1282,7 @@ ReportSlotInvalidation(ReplicationSlotInvalidationCause cause,
                        break;
 
                case RS_INVAL_WAL_LEVEL:
-                       appendStringInfo(&err_detail, _("Logical decoding on standby requires wal_level >= logical on the primary server."));
+                       appendStringInfoString(&err_detail, _("Logical decoding on standby requires wal_level >= logical on the primary server."));
                        break;
                case RS_INVAL_NONE:
                        pg_unreachable();
index 8d5eac47916112d011406518abcb2aecba97001c..442205382e39f66e8067517dedfd90a455f3151d 100644 (file)
@@ -10395,7 +10395,7 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
 
                case F_IS_NORMALIZED:
                        /* IS xxx NORMALIZED */
-                       appendStringInfoString(buf, "(");
+                       appendStringInfoChar(buf, '(');
                        get_rule_expr_paren((Node *) linitial(expr->args), context, false,
                                                                (Node *) expr);
                        appendStringInfoString(buf, " IS");
@@ -10884,7 +10884,7 @@ get_json_constructor(JsonConstructorExpr *ctor, deparse_context *context,
        }
 
        get_json_constructor_options(ctor, buf);
-       appendStringInfo(buf, ")");
+       appendStringInfoChar(buf, ')');
 }
 
 /*
index ec67588cf58f0f2357fe6cf82b43da6f574c7ed1..7f704da730b3b5263118dbb599a23a26ebb73a14 100644 (file)
@@ -2339,9 +2339,9 @@ regression_main(int argc, char *argv[],
                                                         bindir ? "/" : "",
                                                         temp_instance);
                        if (debug)
-                               appendStringInfo(&cmd, " --debug");
+                               appendStringInfoString(&cmd, " --debug");
                        if (nolocale)
-                               appendStringInfo(&cmd, " --no-locale");
+                               appendStringInfoString(&cmd, " --no-locale");
                        appendStringInfo(&cmd, " > \"%s/log/initdb.log\" 2>&1", outputdir);
                        fflush(NULL);
                        if (system(cmd.data))