Re: Duplicated assignment of slot_name in walsender.c - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Duplicated assignment of slot_name in walsender.c
Date
Msg-id 47814.1445469069@sss.pgh.pa.us
Whole thread Raw
In response to Re: Duplicated assignment of slot_name in walsender.c  (Alvaro Herrera <alvherre@2ndquadrant.com>)
List pgsql-hackers
Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> Andres Freund wrote:
>> for another every decent compiler can optimize those away. Note that
>> those duplicate strlen() calls are there in a lot of places in
>> walsender.c

> It can?  Tom has repeatedly argue the opposite, in the past.

I'm prepared to believe that *some* compilers do that, but I think it's
doubtful that they all do.  Even if they do, it would have to be a very
tightly constrained optimization, since the compiler would have to be able
to prove that there is no way for the referenced string to get changed
between the two call sites.  That would likely mean that some places where
you think this will happen will actually end up doing the strlen() twice.

I'm willing to buy the argument that performance doesn't matter in this
particular context; but if we think it does, I'd rather see us explicitly
save and re-use the strlen() result, so that the code behaves the same on
every platform.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Thomas Munro
Date:
Subject: Re: bugs and bug tracking
Next
From: Petr Jelinek
Date:
Subject: Re: WIP: Rework access method interface