Re: Use appendStringInfoSpaces more - Mailing list pgsql-hackers

From Peter Smith
Subject Re: Use appendStringInfoSpaces more
Date
Msg-id CAHut+Pspx8K8GSVLH4UbvQffSJABbXwsYOH+0xB5jC61k-oUqw@mail.gmail.com
Whole thread Raw
In response to Use appendStringInfoSpaces more  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Use appendStringInfoSpaces more
Re: Use appendStringInfoSpaces more
List pgsql-hackers
On Thu, Jan 19, 2023 at 8:45 PM David Rowley <dgrowleyml@gmail.com> wrote:
>
> In [1] I noticed a bit of a poor usage of appendStringInfoString which
> just appends 4 spaces in a loop, one for each indent level of the
> jsonb.  It should be better just to use appendStringInfoSpaces and
> just append all the spaces in one go rather than appending 4 spaces in
> a loop. That'll save having to check enlargeStringInfo() once for each
> loop.
>

Should the add_indent function also have a check to avoid making
unnecessary calls to appendStringInfoSpaces when the level is 0?

e.g.
if (indent)
{
    appendStringInfoCharMacro(out, '\n');
    if (level > 0)
        appendStringInfoSpaces(out, level * 4);
 }

V.

if (indent)
{
    appendStringInfoCharMacro(out, '\n');
    appendStringInfoSpaces(out, level * 4);
 }

------
Kind Regards,
Peter Smith.
Fujitsu Australia



pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Decoupling antiwraparound autovacuum from special rules around auto cancellation
Next
From: Tom Lane
Date:
Subject: Re: Use appendStringInfoSpaces more