Change some unnecessary MemSet calls
authorPeter Eisentraut <peter@eisentraut.org>
Thu, 30 Jun 2022 22:16:38 +0000 (00:16 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Thu, 30 Jun 2022 22:16:38 +0000 (00:16 +0200)
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
contrib/intarray/_intbig_gist.c
contrib/ltree/_ltree_gist.c
contrib/oid2name/oid2name.c
contrib/pg_trgm/trgm_gist.c
src/backend/access/hash/hashovfl.c
src/backend/replication/walreceiver.c
src/backend/utils/adt/tsgistidx.c

index 102c9cea72961c203b1238b82d8e6b51c53b41bf..016bfa4a4c0f96f87128b94a92a4c8b1677c49e5 100644 (file)
@@ -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
                        {
index 18ecd8cda6b14629ca88eeff51c05a6b9022e04a..c9d8f9b84ddd385c7f5c551e5023c9618272b398 100644 (file)
@@ -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
                        {
index 72516c3b6b90477b71cbeb3cb493ae2da892d39b..2dc59f8a0f0ae29956b78dade60cfd19dc4b60d9 100644 (file)
@@ -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
                        {
index a62a5eedb12224559d55b79ff0ae93c0aafb6a5e..a3e358bb1be7d69e1c417ead1dcea1e2e74308a7 100644 (file)
@@ -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);
index 6f28db7d1edb19a1b487ab559723b105b28aea70..7a7be807af16a4fb4d325d2ba0cac4972e6fe6d3 100644 (file)
@@ -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
                        {
index e34cfc302d38015486bc385b566c9d2799bceb57..86aa48d520b18195c0fd77fd743e458dd638e7de 100644 (file)
@@ -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
index 9452932d59039a1fa1176c9f930b8bf0aa326e84..3d37c1fe62e9fc4e41f59add19b912c4cdcad71c 100644 (file)
@@ -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
        {
index b8fd96dd7b0098845761ccf8edbf51c50222edf0..47daf8199ef3fb5ad29f04cfad2fdf23648cfdda 100644 (file)
@@ -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
                        {