Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage) - Mailing list pgsql-hackers

From David Rowley
Subject Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)
Date
Msg-id CAApHDvq_-Q4U4uYUKud2KoD2OqO_DM+isDMGw3ccJq7EiM3hog@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)  (Ranier Vilela <ranier.vf@gmail.com>)
Responses Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)
List pgsql-hackers
On Mon, 20 Apr 2020 at 11:24, Ranier Vilela <ranier.vf@gmail.com> wrote:
> I tried: https://godbolt.org with:
>
> -O2:
>
> f1:
> int main (int argv, char **argc)
> {
>     return strlen(argc[0]) == 0;
> }
>
> f1: Assembly
> main:                                   # @main
>         mov     rcx, qword ptr [rsi]
>         xor     eax, eax
>         cmp     byte ptr [rcx], 0
>         sete    al
>         ret
>
> f2:
> int main (int argv, char **argc)
> {
>     return argc[0] == '\0';
> }
>
> f2: Assembly
>
> main:                                   # @main
>         xor     eax, eax
>         cmp     qword ptr [rsi], 0
>         sete    al
>         ret
>
> For me clearly str [0] == '\ 0', wins.

I think you'd want to use argc[0][0] == '\0' or *argc[0] == '\0'.
Otherwise you appear just to be checking if the first element in the
argc pointer array is set to NULL, which is certainly not the same as
an empty string.

David



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: sqlsmith crash incremental sort
Next
From: Jeff Davis
Date:
Subject: Re: v13: Performance regression related to FORTIFY_SOURCE