From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | David Rowley <dgrowleyml(at)gmail(dot)com> |
Cc: | Japin Li <japinli(at)hotmail(dot)com>, ranier(dot)vf(at)gmail(dot)com, amit(dot)kapila16(at)gmail(dot)com, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Remove redundant strlen call in ReplicationSlotValidateName |
Date: | 2021-07-16 15:37:34 |
Message-ID: | 202107161537.prx67fbp5fzd@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2021-Jul-16, David Rowley wrote:
> On Fri, 16 Jul 2021 at 20:35, Japin Li <japinli(at)hotmail(dot)com> wrote:
> > > When I fix a bug about ALTER SUBSCRIPTION ... SET (slot_name) [1], Ranier Vilela
> > > finds that ReplicationSlotValidateName() has redundant strlen() call, Since it's
> > > not related to that problem, so I start a new thread to discuss it.
>
> I think this is a waste of time. The first strlen() call is just
> checking for an empty string. I imagine all compilers would just
> optimise that to checking if the first char is '\0';
I could find the following idioms
95 times: var[0] == '\0'
146 times: *var == '\0'
35 times: strlen(var) == 0
Resp.
git grep "[a-zA-Z_]*\[0\] == '\\\\0"
git grep "\*[a-zA-Z_]* == '\\\\0"
git grep "strlen([^)]*) == 0"
See https://postgr.es/m/13847.1587332283@sss.pgh.pa.us about replacing
strlen with a check on first byte being zero. So still not Ranier's
patch, but rather the attached. I doubt this change is worth committing
on its own, though, since performance-wise it doesn't matter at all; if
somebody were to make it so that all "strlen(foo) == 0" occurrences were
changed to use the test on byte 0, that could be said to be establishing
a consistent style, which might be more pallatable.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Just treat us the way you want to be treated + some extra allowance
for ignorance." (Michael Brusser)
Attachment | Content-Type | Size |
---|---|---|
no-strlen.patch | text/x-diff | 396 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Ranier Vilela | 2021-07-16 16:18:20 | Re: Remove redundant strlen call in ReplicationSlotValidateName |
Previous Message | James Coleman | 2021-07-16 15:37:15 | Re: Early Sort/Group resjunk column elimination. |