Commit 1e6a7598 authored by David Rowley's avatar David Rowley

Use appendBinaryStringInfo in more places where the length is known

When we already know the length that we're going to append, then it
makes sense to use appendBinaryStringInfo instead of
appendStringInfoString so that the append can be performed with a simple
memcpy() using a known length rather than having to first perform a
strlen() call to obtain the length.

Discussion: https://postgr.es/m/CAKJS1f8+FRAM1s5+mAa3isajeEoAaicJ=4e0WzrH3tAusbbiMQ@mail.gmail.com
parent 19781729
......@@ -1531,7 +1531,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
{
Assert(fpinfo->jointype == JOIN_INNER);
Assert(fpinfo->joinclauses == NIL);
appendStringInfoString(buf, join_sql_o.data);
appendBinaryStringInfo(buf, join_sql_o.data, join_sql_o.len);
return;
}
}
......@@ -1552,7 +1552,7 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
{
Assert(fpinfo->jointype == JOIN_INNER);
Assert(fpinfo->joinclauses == NIL);
appendStringInfoString(buf, join_sql_i.data);
appendBinaryStringInfo(buf, join_sql_i.data, join_sql_i.len);
return;
}
}
......
......@@ -2290,7 +2290,7 @@ ExecBuildSlotValueDescription(Oid reloid,
/* truncate if needed */
vallen = strlen(val);
if (vallen <= maxfieldlen)
appendStringInfoString(&buf, val);
appendBinaryStringInfo(&buf, val, vallen);
else
{
vallen = pg_mbcliplen(val, vallen, maxfieldlen);
......@@ -2309,7 +2309,7 @@ ExecBuildSlotValueDescription(Oid reloid,
if (!table_perm)
{
appendStringInfoString(&collist, ") = ");
appendStringInfoString(&collist, buf.data);
appendBinaryStringInfo(&collist, buf.data, buf.len);
return collist.data;
}
......
......@@ -1406,7 +1406,7 @@ ExecBuildSlotPartitionKeyDescription(Relation rel,
/* truncate if needed */
vallen = strlen(val);
if (vallen <= maxfieldlen)
appendStringInfoString(&buf, val);
appendBinaryStringInfo(&buf, val, vallen);
else
{
vallen = pg_mbcliplen(val, vallen, maxfieldlen);
......
......@@ -1115,7 +1115,7 @@ DeadLockReport(void)
}
/* Duplicate all the above for the server ... */
appendStringInfoString(&logbuf, clientbuf.data);
appendBinaryStringInfo(&logbuf, clientbuf.data, clientbuf.len);
/* ... and add info about query strings */
for (i = 0; i < nDeadlockDetails; i++)
......
......@@ -927,7 +927,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
queryoids[i] = pk_type;
queryoids[j] = pk_type;
}
appendStringInfoString(&querybuf, qualbuf.data);
appendBinaryStringInfo(&querybuf, qualbuf.data, qualbuf.len);
/* Prepare and save the plan */
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys * 2, queryoids,
......@@ -1106,7 +1106,7 @@ ri_set(TriggerData *trigdata, bool is_set_null)
qualsep = "AND";
queryoids[i] = pk_type;
}
appendStringInfoString(&querybuf, qualbuf.data);
appendBinaryStringInfo(&querybuf, qualbuf.data, qualbuf.len);
/* Prepare and save the plan */
qplan = ri_PlanCheck(querybuf.data, riinfo->nkeys, queryoids,
......
......@@ -2804,9 +2804,9 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
appendStringInfoChar(&dq, 'x');
appendStringInfoChar(&dq, '$');
appendStringInfoString(&buf, dq.data);
appendBinaryStringInfo(&buf, dq.data, dq.len);
appendStringInfoString(&buf, prosrc);
appendStringInfoString(&buf, dq.data);
appendBinaryStringInfo(&buf, dq.data, dq.len);
appendStringInfoChar(&buf, '\n');
......@@ -2930,7 +2930,7 @@ print_function_rettype(StringInfo buf, HeapTuple proctup)
appendStringInfoString(&rbuf, format_type_be(proc->prorettype));
}
appendStringInfoString(buf, rbuf.data);
appendBinaryStringInfo(buf, rbuf.data, rbuf.len);
}
/*
......@@ -5682,7 +5682,7 @@ get_target_list(List *targetList, deparse_context *context,
}
/* Add the new field */
appendStringInfoString(buf, targetbuf.data);
appendBinaryStringInfo(buf, targetbuf.data, targetbuf.len);
}
/* clean up */
......@@ -9987,7 +9987,7 @@ get_from_clause(Query *query, const char *prefix, deparse_context *context)
}
/* Add the new item */
appendStringInfoString(buf, itembuf.data);
appendBinaryStringInfo(buf, itembuf.data, itembuf.len);
/* clean up */
pfree(itembuf.data);
......
......@@ -559,7 +559,7 @@ xmlconcat(List *args)
0,
global_standalone);
appendStringInfoString(&buf2, buf.data);
appendBinaryStringInfo(&buf2, buf.data, buf.len);
buf = buf2;
}
......@@ -1879,7 +1879,8 @@ xml_errorHandler(void *data, xmlErrorPtr error)
if (xmlerrcxt->strictness == PG_XML_STRICTNESS_LEGACY)
{
appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data);
appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data,
errorBuf->len);
pfree(errorBuf->data);
pfree(errorBuf);
......@@ -1897,7 +1898,8 @@ xml_errorHandler(void *data, xmlErrorPtr error)
if (level >= XML_ERR_ERROR)
{
appendStringInfoLineSeparator(&xmlerrcxt->err_buf);
appendStringInfoString(&xmlerrcxt->err_buf, errorBuf->data);
appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data,
errorBuf->len);
xmlerrcxt->err_occurred = true;
}
......@@ -2874,7 +2876,7 @@ schema_to_xml_internal(Oid nspid, const char *xmlschema, bool nulls,
subres = table_to_xml_internal(relid, NULL, nulls, tableforest,
targetns, false);
appendStringInfoString(result, subres->data);
appendBinaryStringInfo(result, subres->data, subres->len);
appendStringInfoChar(result, '\n');
}
......@@ -3049,7 +3051,7 @@ database_to_xml_internal(const char *xmlschema, bool nulls,
subres = schema_to_xml_internal(nspid, NULL, nulls,
tableforest, targetns, false);
appendStringInfoString(result, subres->data);
appendBinaryStringInfo(result, subres->data, subres->len);
appendStringInfoChar(result, '\n');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment