Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: Justin Pryzby <pryzby(at)telsasoft(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid unecessary MemSet call (src/backend/utils/cache/relcache.c)
Date: 2022-07-07 11:53:29
Message-ID: CAEudQAopYew853Su+YU1+ZBcXYPyz5GeymptNV4KJJWyeW9nAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qui., 7 de jul. de 2022 às 08:00, Peter Eisentraut <
peter(dot)eisentraut(at)enterprisedb(dot)com> escreveu:

> On 18.05.22 15:52, Peter Eisentraut wrote:
> > On 18.05.22 01:18, Justin Pryzby wrote:
> >> Take the first one as an example. It says:
> >>
> >> GenericCosts costs;
> >> MemSet(&costs, 0, sizeof(costs));
> >>
> >> You sent a patch to change it to sizeof(GenericCosts).
> >>
> >> But it's not a pointer, so they are the same.
> >
> > This instance can more easily be written as
> >
> > costs = {0};
>
> The attached patch replaces all MemSet() calls with struct
> initialization where that is easily possible. (For example, some cases
> have to worry about padding bits, so I left those.)
>
Sounds great.

#include <stdio.h>
#include <string.h>

int main(void) {
bool nulls[4] = {0};
int i;

memset(nulls, 0, sizeof(nulls));

for(i = 0; i < 4; i++)
{
nulls[i] = 0;
}

return 1;
}

main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-8], 0 // bool nulls[4] = {0}; lea
rax, [rbp-8]
mov edx, 4
mov esi, 0
mov rdi, rax
call memset
mov DWORD PTR [rbp-4], 0
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-4]
cdqe
mov BYTE PTR [rbp-8+rax], 0
add DWORD PTR [rbp-4], 1
.L2:
cmp DWORD PTR [rbp-4], 3
jle .L3
mov eax, 1
leave
ret

Only one line using {0}.

+1

regards,
Ranier Vilela

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2022-07-07 12:30:10 Re: Schema variables - new implementation for Postgres 15
Previous Message Dilip Kumar 2022-07-07 11:44:48 Re: making relfilenodes 56 bits