Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)

Поиск
Список
Период
Сортировка
От Ranier Vilela
Тема Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)
Дата
Msg-id CAEudQArL0oaM=Rx9UetpLTEQ=yeT0DEAKSqHibhDbFAacbQh+w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [PATCH] Small optimization across postgres (remove strlenduplicate usage)  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers
Em dom., 19 de abr. de 2020 às 22:00, David Rowley <dgrowleyml@gmail.com> escreveu:
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.
I guess you're right.

x86-64 clang (trunk) -O2
f1:
int cmp(const char * name)
{
    return strlen(name) == 0;
}

cmp:                                    # @cmp
        xor     eax, eax
        cmp     byte ptr [rdi], 0
        sete    al
        ret

f2:
int cmp(const char * name)
{
    return name[0] == '\0';
}

cmp:                                    # @cmp
        xor     eax, eax
        cmp     byte ptr [rdi], 0
        sete    al
        ret

Is the same result in assembly.
Well, it doesn't matter to me, I will continue to use str[0] == '\0'.

Thanks for take part.

regards,
Ranier VIlela

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

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Re: where should I stick that backup?
Следующее
От: Dilip Kumar
Дата:
Сообщение: Re: fixing old_snapshot_threshold's time->xid mapping