Re: Remove redundant strlen call in ReplicationSlotValidateName
От | Ranier Vilela |
---|---|
Тема | Re: Remove redundant strlen call in ReplicationSlotValidateName |
Дата | |
Msg-id | CAEudQAp_RG3bAF0D5pYjLToFvLQO86ewJM5g4X5OedUQsTq-zg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Remove redundant strlen call in ReplicationSlotValidateName (David Rowley <dgrowleyml@gmail.com>) |
Список | pgsql-hackers |
Em sex., 16 de jul. de 2021 às 07:05, David Rowley <dgrowleyml@gmail.com> escreveu:
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 think with very simple functions, the compiler can do the job.
But, it's not always like that, I think.
With gcc 11, I can see clear and different ASM.
strlen1(char const*):
sub rsp, 8
cmp BYTE PTR [rdi], 0
je .L8
call strlen
mov r8, rax
xor eax, eax
cmp r8, 64
ja .L9
strlen2(char const*):
sub rsp, 8
call strlen
test eax, eax
je .L15
xor r8d, r8d
cmp eax, 64
jg .L16
For me strlen2's ASM is much more compact.
And as some functions with strlen are always a hotpath, it's worth it.
And as some functions with strlen are always a hotpath, it's worth it.
regards,
Ranier Vilela
В списке pgsql-hackers по дате отправления: