Re: Remove redundant strlen call in ReplicationSlotValidateName

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Remove redundant strlen call in ReplicationSlotValidateName
Дата
Msg-id 202107161537.prx67fbp5fzd@alvherre.pgsql
обсуждение исходный текст
Ответ на Re: Remove redundant strlen call in ReplicationSlotValidateName  (David Rowley <dgrowleyml@gmail.com>)
Ответы Re: Remove redundant strlen call in ReplicationSlotValidateName
Список pgsql-hackers
On 2021-Jul-16, David Rowley wrote:

> On Fri, 16 Jul 2021 at 20:35, Japin Li <japinli@hotmail.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)

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: James Coleman
Дата:
Сообщение: Re: Early Sort/Group resjunk column elimination.
Следующее
От: Ranier Vilela
Дата:
Сообщение: Re: Remove redundant strlen call in ReplicationSlotValidateName