1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Use appendStringInfoString instead of appendStringInfo where possible.

This shaves a few cycles, and generally seems like good programming
practice.

David Rowley
This commit is contained in:
Robert Haas
2013-10-31 10:55:59 -04:00
parent 343bb134ea
commit cacbdd7810
33 changed files with 399 additions and 404 deletions

View File

@ -335,18 +335,18 @@ cube_out(PG_FUNCTION_ARGS)
for (i = 0; i < dim; i++)
{
if (i > 0)
appendStringInfo(&buf, ", ");
appendStringInfoString(&buf, ", ");
appendStringInfo(&buf, "%.*g", ndig, LL_COORD(cube, i));
}
appendStringInfoChar(&buf, ')');
if (!cube_is_point_internal(cube))
{
appendStringInfo(&buf, ",(");
appendStringInfoString(&buf, ",(");
for (i = 0; i < dim; i++)
{
if (i > 0)
appendStringInfo(&buf, ", ");
appendStringInfoString(&buf, ", ");
appendStringInfo(&buf, "%.*g", ndig, UR_COORD(cube, i));
}
appendStringInfoChar(&buf, ')');

View File

@ -2169,14 +2169,14 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
continue;
if (needComma)
appendStringInfo(&buf, ",");
appendStringInfoChar(&buf, ',');
appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
needComma = true;
}
appendStringInfo(&buf, ") VALUES(");
appendStringInfoString(&buf, ") VALUES(");
/*
* Note: i is physical column number (counting from 0).
@ -2188,7 +2188,7 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
continue;
if (needComma)
appendStringInfo(&buf, ",");
appendStringInfoChar(&buf, ',');
key = get_attnum_pk_pos(pkattnums, pknumatts, i);
@ -2203,10 +2203,10 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
pfree(val);
}
else
appendStringInfo(&buf, "NULL");
appendStringInfoString(&buf, "NULL");
needComma = true;
}
appendStringInfo(&buf, ")");
appendStringInfoChar(&buf, ')');
return (buf.data);
}
@ -2232,7 +2232,7 @@ get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals
int pkattnum = pkattnums[i];
if (i > 0)
appendStringInfo(&buf, " AND ");
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
@ -2241,7 +2241,7 @@ get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals
appendStringInfo(&buf, " = %s",
quote_literal_cstr(tgt_pkattvals[i]));
else
appendStringInfo(&buf, " IS NULL");
appendStringInfoString(&buf, " IS NULL");
}
return (buf.data);
@ -2286,7 +2286,7 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
continue;
if (needComma)
appendStringInfo(&buf, ", ");
appendStringInfoString(&buf, ", ");
appendStringInfo(&buf, "%s = ",
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
@ -2308,16 +2308,16 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
needComma = true;
}
appendStringInfo(&buf, " WHERE ");
appendStringInfoString(&buf, " WHERE ");
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
if (i > 0)
appendStringInfo(&buf, " AND ");
appendStringInfoString(&buf, " AND ");
appendStringInfo(&buf, "%s",
appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
val = tgt_pkattvals[i];
@ -2325,7 +2325,7 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
if (val != NULL)
appendStringInfo(&buf, " = %s", quote_literal_cstr(val));
else
appendStringInfo(&buf, " IS NULL");
appendStringInfoString(&buf, " IS NULL");
}
return (buf.data);
@ -2419,7 +2419,7 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
int pkattnum = pkattnums[i];
if (i > 0)
appendStringInfo(&buf, " AND ");
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
@ -2428,7 +2428,7 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
appendStringInfo(&buf, " = %s",
quote_literal_cstr(src_pkattvals[i]));
else
appendStringInfo(&buf, " IS NULL");
appendStringInfoString(&buf, " IS NULL");
}
/*

View File

@ -1972,7 +1972,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
initStringInfo(&buf);
appendStringInfo(&buf, "\ndigraph sourceNFA {\n");
appendStringInfoString(&buf, "\ndigraph sourceNFA {\n");
for (state = 0; state < nstates; state++)
{
@ -1982,8 +1982,8 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
appendStringInfo(&buf, "s%d", state);
if (pg_reg_getfinalstate(regex) == state)
appendStringInfo(&buf, " [shape = doublecircle]");
appendStringInfo(&buf, ";\n");
appendStringInfoString(&buf, " [shape = doublecircle]");
appendStringInfoString(&buf, ";\n");
arcsCount = pg_reg_getnumoutarcs(regex, state);
arcs = (regex_arc_t *) palloc(sizeof(regex_arc_t) * arcsCount);
@ -1998,13 +1998,13 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
pfree(arcs);
}
appendStringInfo(&buf, " node [shape = point ]; initial;\n");
appendStringInfoString(&buf, " node [shape = point ]; initial;\n");
appendStringInfo(&buf, " initial -> s%d;\n",
pg_reg_getinitialstate(regex));
/* Print colors */
appendStringInfo(&buf, " { rank = sink;\n");
appendStringInfo(&buf, " Colors [shape = none, margin=0, label=<\n");
appendStringInfoString(&buf, " { rank = sink;\n");
appendStringInfoString(&buf, " Colors [shape = none, margin=0, label=<\n");
for (i = 0; i < ncolors; i++)
{
@ -2020,17 +2020,17 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
memcpy(s, color->wordChars[j].bytes, MAX_MULTIBYTE_CHAR_LEN);
s[MAX_MULTIBYTE_CHAR_LEN] = '\0';
appendStringInfo(&buf, "%s", s);
appendStringInfoString(&buf, s);
}
}
else
appendStringInfo(&buf, "not expandable");
appendStringInfo(&buf, "\n");
appendStringInfoString(&buf, "not expandable");
appendStringInfoChar(&buf, '\n');
}
appendStringInfo(&buf, " >];\n");
appendStringInfo(&buf, " }\n");
appendStringInfo(&buf, "}\n");
appendStringInfoString(&buf, " >];\n");
appendStringInfoString(&buf, " }\n");
appendStringInfoString(&buf, "}\n");
{
/* dot -Tpng -o /tmp/source.png < /tmp/source.dot */
@ -2056,7 +2056,7 @@ printTrgmNFA(TrgmNFA *trgmNFA)
initStringInfo(&buf);
appendStringInfo(&buf, "\ndigraph transformedNFA {\n");
appendStringInfoString(&buf, "\ndigraph transformedNFA {\n");
hash_seq_init(&scan_status, trgmNFA->states);
while ((state = (TrgmState *) hash_seq_search(&scan_status)) != NULL)
@ -2065,11 +2065,11 @@ printTrgmNFA(TrgmNFA *trgmNFA)
appendStringInfo(&buf, "s%p", (void *) state);
if (state->fin)
appendStringInfo(&buf, " [shape = doublecircle]");
appendStringInfoString(&buf, " [shape = doublecircle]");
if (state->init)
initstate = state;
appendStringInfo(&buf, " [label = \"%d\"]", state->stateKey.nstate);
appendStringInfo(&buf, ";\n");
appendStringInfoString(&buf, ";\n");
foreach(cell, state->arcs)
{
@ -2078,21 +2078,21 @@ printTrgmNFA(TrgmNFA *trgmNFA)
appendStringInfo(&buf, " s%p -> s%p [label = \"",
(void *) state, (void *) arc->target);
printTrgmColor(&buf, arc->ctrgm.colors[0]);
appendStringInfo(&buf, " ");
appendStringInfoChar(&buf, ' ');
printTrgmColor(&buf, arc->ctrgm.colors[1]);
appendStringInfo(&buf, " ");
appendStringInfoChar(&buf, ' ');
printTrgmColor(&buf, arc->ctrgm.colors[2]);
appendStringInfo(&buf, "\"];\n");
appendStringInfoString(&buf, "\"];\n");
}
}
if (initstate)
{
appendStringInfo(&buf, " node [shape = point ]; initial;\n");
appendStringInfoString(&buf, " node [shape = point ]; initial;\n");
appendStringInfo(&buf, " initial -> s%p;\n", (void *) initstate);
}
appendStringInfo(&buf, "}\n");
appendStringInfoString(&buf, "}\n");
{
/* dot -Tpng -o /tmp/transformed.png < /tmp/transformed.dot */
@ -2112,9 +2112,9 @@ static void
printTrgmColor(StringInfo buf, TrgmColor co)
{
if (co == COLOR_UNKNOWN)
appendStringInfo(buf, "u");
appendStringInfoChar(buf, 'u');
else if (co == COLOR_BLANK)
appendStringInfo(buf, "b");
appendStringInfoChar(buf, 'b');
else
appendStringInfo(buf, "%d", (int) co);
}
@ -2131,7 +2131,7 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)
initStringInfo(&buf);
appendStringInfo(&buf, "\ndigraph packedGraph {\n");
appendStringInfoString(&buf, "\ndigraph packedGraph {\n");
for (i = 0; i < packedGraph->statesCount; i++)
{
@ -2140,7 +2140,7 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)
appendStringInfo(&buf, " s%d", i);
if (i == 1)
appendStringInfo(&buf, " [shape = doublecircle]");
appendStringInfoString(&buf, " [shape = doublecircle]");
appendStringInfo(&buf, " [label = <s%d>];\n", i);
@ -2153,12 +2153,12 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)
}
}
appendStringInfo(&buf, " node [shape = point ]; initial;\n");
appendStringInfoString(&buf, " node [shape = point ]; initial;\n");
appendStringInfo(&buf, " initial -> s%d;\n", 0);
/* Print trigrams */
appendStringInfo(&buf, " { rank = sink;\n");
appendStringInfo(&buf, " Trigrams [shape = none, margin=0, label=<\n");
appendStringInfoString(&buf, " { rank = sink;\n");
appendStringInfoString(&buf, " Trigrams [shape = none, margin=0, label=<\n");
p = GETARR(trigrams);
for (i = 0; i < packedGraph->colorTrigramsCount; i++)
@ -2171,7 +2171,7 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)
for (j = 0; j < count; j++)
{
if (j > 0)
appendStringInfo(&buf, ", ");
appendStringInfoString(&buf, ", ");
/*
* XXX This representation is nice only for all-ASCII trigrams.
@ -2181,9 +2181,9 @@ printTrgmPackedGraph(TrgmPackedGraph *packedGraph, TRGM *trigrams)
}
}
appendStringInfo(&buf, " >];\n");
appendStringInfo(&buf, " }\n");
appendStringInfo(&buf, "}\n");
appendStringInfoString(&buf, " >];\n");
appendStringInfoString(&buf, " }\n");
appendStringInfoString(&buf, "}\n");
{
/* dot -Tpng -o /tmp/packed.png < /tmp/packed.dot */

View File

@ -841,7 +841,7 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
if (targetAttrs)
{
appendStringInfoString(buf, "(");
appendStringInfoChar(buf, '(');
first = true;
foreach(lc, targetAttrs)
@ -869,7 +869,7 @@ deparseInsertSql(StringInfo buf, PlannerInfo *root,
pindex++;
}
appendStringInfoString(buf, ")");
appendStringInfoChar(buf, ')');
}
else
appendStringInfoString(buf, " DEFAULT VALUES");
@ -989,7 +989,7 @@ deparseAnalyzeSizeSql(StringInfo buf, Relation rel)
initStringInfo(&relname);
deparseRelation(&relname, rel);
appendStringInfo(buf, "SELECT pg_catalog.pg_relation_size(");
appendStringInfoString(buf, "SELECT pg_catalog.pg_relation_size(");
deparseStringLiteral(buf, relname.data);
appendStringInfo(buf, "::pg_catalog.regclass) / %d", BLCKSZ);
}
@ -1302,7 +1302,7 @@ deparseConst(Const *node, deparse_expr_cxt *context)
if (node->constisnull)
{
appendStringInfo(buf, "NULL");
appendStringInfoString(buf, "NULL");
appendStringInfo(buf, "::%s",
format_type_with_typemod(node->consttype,
node->consttypmod));
@ -1650,7 +1650,7 @@ deparseOperatorName(StringInfo buf, Form_pg_operator opform)
else
{
/* Just print operator name. */
appendStringInfo(buf, "%s", opname);
appendStringInfoString(buf, opname);
}
}

View File

@ -787,7 +787,7 @@ postgresGetForeignPlan(PlannerInfo *root,
root->parse->commandType == CMD_DELETE))
{
/* Relation is UPDATE/DELETE target, so use FOR UPDATE */
appendStringInfo(&sql, " FOR UPDATE");
appendStringInfoString(&sql, " FOR UPDATE");
}
else
{
@ -808,11 +808,11 @@ postgresGetForeignPlan(PlannerInfo *root,
{
case LCS_FORKEYSHARE:
case LCS_FORSHARE:
appendStringInfo(&sql, " FOR SHARE");
appendStringInfoString(&sql, " FOR SHARE");
break;
case LCS_FORNOKEYUPDATE:
case LCS_FORUPDATE:
appendStringInfo(&sql, " FOR UPDATE");
appendStringInfoString(&sql, " FOR UPDATE");
break;
}
}

View File

@ -1340,7 +1340,7 @@ build_tuplestore_recursively(char *key_fld,
for (i = 0; i < proc; i++)
{
/* initialize branch for this pass */
appendStringInfo(&branchstr, "%s", branch);
appendStringInfoString(&branchstr, branch);
appendStringInfo(&chk_branchstr, "%s%s%s", branch_delim, branch, branch_delim);
/* get the next sql result tuple */