Re: appendStringInfo vs appendStringInfoString

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: appendStringInfo vs appendStringInfoString
Date: 2013-09-28 09:50:10
Message-ID: CAApHDvp4oA-=grh3o-WTm3B0uS89GOq4M6xiYYC27Ycrcub8Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Sep 28, 2013 at 9:44 PM, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:

> I did some benchmarking earlier in the week for the new patch which was
> just commited to allow formatting in the log_line_prefix string. In version
> 0.4 of the patch there was some performance regression as I was doing
> appendStringInfo(buf, "%*s", padding, variable); instead of
> appendStringInfoString(buf, variable); This regression was fixed in a later
> version of the patch by only using appendStringInfo when the padding was 0.
>
> More details here:
> http://www.postgresql.org/message-id/CAApHDvreSGYvtXJvqHcXZL8_tXiKKiFXhQyXgqtnQ5Yo=MEfMg@mail.gmail.com
>
> Today I started looking through the entire source tree to look for places
> where appendStringInfo() could be replaced by appendStringInfoString(), I
> now have a patch which is around 100 KB in size which changes a large
> number of these instances.
>
>
>
...

Also on making the changes I noticed a possible small bug in the code that
could cause a crash if for some reason a translation contained a %s. I know
it is an unlikely scenario, never-the-less here is a patch to fix it.

diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 562a7c9..91da50b 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -372,7 +372,7 @@ incompatible_module_error(const char *libname,
}

if (details.len == 0)
- appendStringInfo(&details,
+ appendStringInfoString(&details,
_("Magic block has unexpected length or padding difference."));

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ian Lawrence Barwick 2013-09-28 10:31:23 Re: plpgsql.print_strict_params
Previous Message David Rowley 2013-09-28 09:44:58 appendStringInfo vs appendStringInfoString