Skip to content

Commit e8d5929

Browse files
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
1 parent 398d3e3 commit e8d5929

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
361361
/* Values only available to role member or pg_read_all_stats */
362362
if (HAS_PGSTAT_PERMISSIONS(beentry->st_userid))
363363
{
364-
SockAddr zero_clientaddr;
365364
char *clipped_activity;
366365

367366
switch (beentry->st_state)
@@ -483,9 +482,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
483482
nulls[11] = true;
484483

485484
/* A zeroed client addr means we don't know */
486-
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
487-
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
488-
sizeof(zero_clientaddr)) == 0)
485+
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
486+
sizeof(beentry->st_clientaddr)))
489487
{
490488
nulls[12] = true;
491489
nulls[13] = true;
@@ -880,7 +878,6 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
880878
{
881879
int32 procNumber = PG_GETARG_INT32(0);
882880
PgBackendStatus *beentry;
883-
SockAddr zero_clientaddr;
884881
char remote_host[NI_MAXHOST];
885882
int ret;
886883

@@ -891,9 +888,8 @@ pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS)
891888
PG_RETURN_NULL();
892889

893890
/* A zeroed client addr means we don't know */
894-
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
895-
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
896-
sizeof(zero_clientaddr)) == 0)
891+
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
892+
sizeof(beentry->st_clientaddr)))
897893
PG_RETURN_NULL();
898894

899895
switch (beentry->st_clientaddr.addr.ss_family)
@@ -925,7 +921,6 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
925921
{
926922
int32 procNumber = PG_GETARG_INT32(0);
927923
PgBackendStatus *beentry;
928-
SockAddr zero_clientaddr;
929924
char remote_port[NI_MAXSERV];
930925
int ret;
931926

@@ -936,9 +931,8 @@ pg_stat_get_backend_client_port(PG_FUNCTION_ARGS)
936931
PG_RETURN_NULL();
937932

938933
/* A zeroed client addr means we don't know */
939-
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
940-
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
941-
sizeof(zero_clientaddr)) == 0)
934+
if (pg_memory_is_all_zeros(&beentry->st_clientaddr,
935+
sizeof(beentry->st_clientaddr)))
942936
PG_RETURN_NULL();
943937

944938
switch (beentry->st_clientaddr.addr.ss_family)

0 commit comments

Comments
 (0)