Re: Remove redundant strlen call in ReplicationSlotValidateName - Mailing list pgsql-hackers

From Ranier Vilela
Subject Re: Remove redundant strlen call in ReplicationSlotValidateName
Date
Msg-id CAEudQAp_RG3bAF0D5pYjLToFvLQO86ewJM5g4X5OedUQsTq-zg@mail.gmail.com
Whole thread Raw
In response to Re: Remove redundant strlen call in ReplicationSlotValidateName  (David Rowley <dgrowleyml@gmail.com>)
List 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     rsp8
        cmp     BYTE PTR [rdi], 0
        je      .L8
        call    strlen
        mov     r8rax
        xor     eaxeax
        cmp     r864
        ja      .L9

strlen2(char const*):
        sub     rsp8
        call    strlen
        test    eaxeax
        je      .L15
        xor     r8dr8d
        cmp     eax64
        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

pgsql-hackers by date:

Previous
From: Japin Li
Date:
Subject: Re: Remove redundant strlen call in ReplicationSlotValidateName
Next
From: Dean Rasheed
Date:
Subject: Re: CREATE COLLATION - check for duplicate options and error out if found one