Use pg_memory_is_all_zeros() in pgstatfuncs.c.

There are a few places in this file that use memset() and memcmp()
to determine whether a section of memory is all zeros.  This commit
modifies them to use pg_memory_is_all_zeros() instead.  These
aren't expected to be hot code paths, but this may optimize them a
bit.  Plus, this allows us to remove some variables that were only
needed for the memset() and memcmp().

Author: Bertrand Drouvot
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/Z1hNubHfvMxlW6eu%40ip-10-97-1-34.eu-west-3.compute.internal
pull/193/head
Nathan Bossart 7 months ago
parent 398d3e3b5b
commit e8d5929428
  1. 18
      src/backend/utils/adt/pgstatfuncs.c

@ -361,7 +361,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
/* Values only available to role member or pg_read_all_stats */
if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
{
SockAddr zero_clientaddr;
char *clipped_activity;
switch (beentry->st_state)
@ -483,9 +482,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
nulls[11] = true;
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
sizeof(beentry->st_clientaddr)))
{
nulls[12] = true;
nulls[13] = true;
@ -880,7 +878,6 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
{
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_host[NI_MAXHOST];
int ret;
@ -891,9 +888,8 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
sizeof(beentry->st_clientaddr)))
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)
@ -925,7 +921,6 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
{
int32 procNumber = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
SockAddr zero_clientaddr;
char remote_port[NI_MAXSERV];
int ret;
@ -936,9 +931,8 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
/* A zeroed client addr means we don't know */
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
sizeof(zero_clientaddr)) == 0)
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
sizeof(beentry->st_clientaddr)))
PG_RETURN_NULL();
switch (beentry->st_clientaddr.addr.ss_family)

Loading…
Cancel
Save