]> Savannah Git Hosting - gnulib.git/commitdiff
xalloc: tune xzalloc for fresh allocations
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Dec 2019 08:49:54 +0000 (00:49 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 17 Dec 2019 08:51:43 +0000 (00:51 -0800)
* lib/xmalloc.c (xzalloc): Use xcalloc rather than xmalloc+memset,
because when the memory is freshly allocated from the OS via sbrk
or mmap, calloc can avoid doing the memset.

ChangeLog
lib/xmalloc.c

index 9806040bb18c59418f3d09319289bcf6646d241e..41d8be0eddf02e324362efcb0f2c1eb00ba95de2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2019-12-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+       xalloc: tune xzalloc for fresh allocations
+       * lib/xmalloc.c (xzalloc): Use xcalloc rather than xmalloc+memset,
+       because when the memory is freshly allocated from the OS via sbrk
+       or mmap, calloc can avoid doing the memset.
+
        dfa: new function dfacopysyntax
        * lib/dfa.c (struct dfa): Move syntax member later so
        that dfacopysyntax can easily clear earlier members.
index cbe9a4f5671e33d96b9cba0e611eec0a06e4c0c2..90f6cdc729f2b6992bb56ae377ca1615d1deb74a 100644 (file)
@@ -76,14 +76,14 @@ x2realloc (void *p, size_t *pn)
   return x2nrealloc (p, pn, 1);
 }
 
-/* Allocate S bytes of zeroed memory dynamically, with error checking.
+/* Allocate N bytes of zeroed memory dynamically, with error checking.
    There's no need for xnzalloc (N, S), since it would be equivalent
    to xcalloc (N, S).  */
 
 void *
-xzalloc (size_t s)
+xzalloc (size_t n)
 {
-  return memset (xmalloc (s), 0, s);
+  return xcalloc (n, 1);
 }
 
 /* Allocate zeroed memory for N elements of S bytes, with error