Em sex., 16 de jul. de 2021 às 07:05, David Rowley <dgrowle...@gmail.com>
escreveu:

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

https://godbolt.org/z/1jdW3zT58

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.

regards,
Ranier Vilela

Reply via email to