From 258f48f858b0bcc4c3fac3fa01f79ee61ad0cd1e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 1 Jul 2022 00:16:38 +0200 Subject: [PATCH] Change some unnecessary MemSet calls MemSet() with a value other than 0 just falls back to memset(), so the indirection is unnecessary if the value is constant and not 0. Since there is some interest in getting rid of MemSet(), this gets some easy cases out of the way. (There are a few MemSet() calls that I didn't change to maintain the consistency with their surrounding code.) Discussion: https://www.postgresql.org/message-id/flat/CAEudQApCeq4JjW1BdnwU=m=-DvG5WyUik0Yfn3p6UNphiHjj+w@mail.gmail.com --- contrib/hstore/hstore_gist.c | 4 ++-- contrib/intarray/_intbig_gist.c | 4 ++-- contrib/ltree/_ltree_gist.c | 4 ++-- contrib/oid2name/oid2name.c | 2 +- contrib/pg_trgm/trgm_gist.c | 4 ++-- src/backend/access/hash/hashovfl.c | 2 +- src/backend/replication/walreceiver.c | 2 +- src/backend/utils/adt/tsgistidx.c | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c index 102c9cea72..016bfa4a4c 100644 --- a/contrib/hstore/hstore_gist.c +++ b/contrib/hstore/hstore_gist.c @@ -459,7 +459,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_l) || ISALLTRUE(_j)) { if (!ISALLTRUE(datum_l)) - MemSet((void *) union_l, 0xff, siglen); + memset((void *) union_l, 0xff, siglen); } else { @@ -475,7 +475,7 @@ ghstore_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_r) || ISALLTRUE(_j)) { if (!ISALLTRUE(datum_r)) - MemSet((void *) union_r, 0xff, siglen); + memset((void *) union_r, 0xff, siglen); } else { diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c index 18ecd8cda6..c9d8f9b84d 100644 --- a/contrib/intarray/_intbig_gist.c +++ b/contrib/intarray/_intbig_gist.c @@ -420,7 +420,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_l) || ISALLTRUE(_j)) { if (!ISALLTRUE(datum_l)) - MemSet((void *) union_l, 0xff, siglen); + memset((void *) union_l, 0xff, siglen); } else { @@ -436,7 +436,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_r) || ISALLTRUE(_j)) { if (!ISALLTRUE(datum_r)) - MemSet((void *) union_r, 0xff, siglen); + memset((void *) union_r, 0xff, siglen); } else { diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c index 72516c3b6b..2dc59f8a0f 100644 --- a/contrib/ltree/_ltree_gist.c +++ b/contrib/ltree/_ltree_gist.c @@ -345,7 +345,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS) if (LTG_ISALLTRUE(datum_l) || LTG_ISALLTRUE(_j)) { if (!LTG_ISALLTRUE(datum_l)) - MemSet((void *) union_l, 0xff, siglen); + memset((void *) union_l, 0xff, siglen); } else { @@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS) if (LTG_ISALLTRUE(datum_r) || LTG_ISALLTRUE(_j)) { if (!LTG_ISALLTRUE(datum_r)) - MemSet((void *) union_r, 0xff, siglen); + memset((void *) union_r, 0xff, siglen); } else { diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c index a62a5eedb1..a3e358bb1b 100644 --- a/contrib/oid2name/oid2name.c +++ b/contrib/oid2name/oid2name.c @@ -424,7 +424,7 @@ sql_exec(PGconn *conn, const char *todo, bool quiet) } fprintf(stdout, "\n"); pad = (char *) pg_malloc(l + 1); - MemSet(pad, '-', l); + memset(pad, '-', l); pad[l] = '\0'; fprintf(stdout, "%s\n", pad); free(pad); diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c index 6f28db7d1e..7a7be807af 100644 --- a/contrib/pg_trgm/trgm_gist.c +++ b/contrib/pg_trgm/trgm_gist.c @@ -914,7 +914,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_l) || cache[j].allistrue) { if (!ISALLTRUE(datum_l)) - MemSet((void *) GETSIGN(datum_l), 0xff, siglen); + memset((void *) GETSIGN(datum_l), 0xff, siglen); } else { @@ -930,7 +930,7 @@ gtrgm_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_r) || cache[j].allistrue) { if (!ISALLTRUE(datum_r)) - MemSet((void *) GETSIGN(datum_r), 0xff, siglen); + memset((void *) GETSIGN(datum_r), 0xff, siglen); } else { diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c index e34cfc302d..86aa48d520 100644 --- a/src/backend/access/hash/hashovfl.c +++ b/src/backend/access/hash/hashovfl.c @@ -760,7 +760,7 @@ _hash_initbitmapbuffer(Buffer buf, uint16 bmsize, bool initpage) /* set all of the bits to 1 */ freep = HashPageGetBitmap(pg); - MemSet(freep, 0xFF, bmsize); + memset(freep, 0xFF, bmsize); /* * Set pd_lower just past the end of the bitmap page data. We could even diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 9452932d59..3d37c1fe62 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -1410,7 +1410,7 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS) * see details. Other users only get the pid value to know whether it * is a WAL receiver, but no details. */ - MemSet(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); + memset(&nulls[1], true, sizeof(bool) * (tupdesc->natts - 1)); } else { diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c index b8fd96dd7b..47daf8199e 100644 --- a/src/backend/utils/adt/tsgistidx.c +++ b/src/backend/utils/adt/tsgistidx.c @@ -753,7 +753,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_l) || cache[j].allistrue) { if (!ISALLTRUE(datum_l)) - MemSet((void *) GETSIGN(datum_l), 0xff, siglen); + memset((void *) GETSIGN(datum_l), 0xff, siglen); } else { @@ -769,7 +769,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS) if (ISALLTRUE(datum_r) || cache[j].allistrue) { if (!ISALLTRUE(datum_r)) - MemSet((void *) GETSIGN(datum_r), 0xff, siglen); + memset((void *) GETSIGN(datum_r), 0xff, siglen); } else {