diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-12-11 14:19:14 -0600 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-12-11 14:19:14 -0600 |
commit | e8d59294282bd01bc06f2af13c79b9155024a917 (patch) | |
tree | 33066feed5bb93d88afd0ca7207cc2f34fc58833 /src/backend/utils/adt/pgstatfuncs.c | |
parent | 398d3e3b5b8f4c81795e07655f28036839cc0550 (diff) | |
download | postgresql-e8d59294282bd01bc06f2af13c79b9155024a917.tar.gz postgresql-e8d59294282bd01bc06f2af13c79b9155024a917.zip |
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
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r-- | src/backend/utils/adt/pgstatfuncs.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 60a397dc561..cdf37403e9d 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/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) |