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

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Cc: Justin Pryzby <pryzby@telsasoft.com>, Ranier Vilela <ranier.vf@gmail.com>, David Rowley <dgrowleyml@gmail.com>, pgsql-hackers@postgresql.org
Date: 2022-07-07T11:16:07Z
Lists: pgsql-hackers
On 2022-Jul-07, Peter Eisentraut wrote:

> diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
> index 4445a86aee..79b23fa7d7 100644
> --- a/src/bin/pg_basebackup/pg_basebackup.c
> +++ b/src/bin/pg_basebackup/pg_basebackup.c

> @@ -1952,7 +1948,6 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
>  	else
>  		starttli = latesttli;
>  	PQclear(res);
> -	MemSet(xlogend, 0, sizeof(xlogend));
>  
>  	if (verbose && includewal != NO_WAL)
>  		pg_log_info("write-ahead log start point: %s on timeline %u",

You removed the MemSet here, but there's no corresponding
initialization.

> diff --git a/src/port/snprintf.c b/src/port/snprintf.c
> index abb1c59770..e646b0e642 100644
> --- a/src/port/snprintf.c
> +++ b/src/port/snprintf.c
> @@ -756,12 +756,9 @@ find_arguments(const char *format, va_list args,
>  	int			longflag;
>  	int			fmtpos;
>  	int			i;
> -	int			last_dollar;
> -	PrintfArgType argtypes[PG_NL_ARGMAX + 1];
> -
>  	/* Initialize to "no dollar arguments known" */
> -	last_dollar = 0;
> -	MemSet(argtypes, 0, sizeof(argtypes));
> +	int			last_dollar = 0;
> +	PrintfArgType argtypes[PG_NL_ARGMAX + 1] = {0};

pgindent will insert a blank line before the comment, which I personally
find quite ugly (because it splits the block of declarations).

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"El Maquinismo fue proscrito so pena de cosquilleo hasta la muerte"
(Ijon Tichy en Viajes, Stanislaw Lem)



Commits

  1. Replace many MemSet calls with struct initialization

  2. Change some unnecessary MemSet calls

  3. Avoid unnecessary MemSet call