From: Paul Eggert Date: Tue, 17 Dec 2019 08:49:54 +0000 (-0800) Subject: xalloc: tune xzalloc for fresh allocations X-Git-Tag: v1.0~4496 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f1a80e85ea35efcae290e1be5a85df735701fc4f;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 9806040bb1..41d8be0edd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-12-17 Paul Eggert + 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. diff --git a/lib/xmalloc.c b/lib/xmalloc.c index cbe9a4f567..90f6cdc729 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c @@ -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