Let zalloc() use calloc() if it's available
authorFabian Keil <fk@fabiankeil.de>
Mon, 29 May 2017 10:05:46 +0000 (10:05 +0000)
committerFabian Keil <fk@fabiankeil.de>
Mon, 29 May 2017 10:05:46 +0000 (10:05 +0000)
In some situations using calloc() can be faster than
malloc() + memset() and it should never be slower.

In the real world the impact of this change is not
expected to be noticeable.

Sponsored by: Robert Klemme

configure.in
miscutil.c

index f905bcf..b75d90a 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl
 dnl Process this file with autoconf to produce a configure script.
 dnl
-dnl $Id: configure.in,v 1.212 2017/05/25 11:14:53 fabiankeil Exp $
+dnl $Id: configure.in,v 1.213 2017/05/25 11:17:11 fabiankeil Exp $
 dnl
 dnl Written by and Copyright (C) 2001-2017 the
 dnl Privoxy team. https://www.privoxy.org/
 dnl
 dnl Written by and Copyright (C) 2001-2017 the
 dnl Privoxy team. https://www.privoxy.org/
@@ -32,7 +32,7 @@ dnl =================================================================
 dnl AutoConf Initialization
 dnl =================================================================
 
 dnl AutoConf Initialization
 dnl =================================================================
 
-AC_REVISION($Revision: 1.212 $)
+AC_REVISION($Revision: 1.213 $)
 AC_INIT(jcc.c)
 
 if test ! -f config.h.in; then
 AC_INIT(jcc.c)
 
 if test ! -f config.h.in; then
@@ -782,6 +782,7 @@ AC_CHECK_FUNCS([ \
  access \
  arc4random \
  atexit \
  access \
  arc4random \
  atexit \
+ calloc \
  getcwd \
  gethostbyaddr \
  gethostbyaddr_r \
  getcwd \
  gethostbyaddr \
  gethostbyaddr_r \
index 4a9b88f..ea2c3aa 100644 (file)
@@ -1,4 +1,4 @@
-const char miscutil_rcs[] = "$Id: miscutil.c,v 1.82 2016/07/23 23:05:15 ler762 Exp $";
+const char miscutil_rcs[] = "$Id: miscutil.c,v 1.83 2017/05/04 14:34:18 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/miscutil.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/miscutil.c,v $
@@ -71,22 +71,27 @@ const char miscutil_h_rcs[] = MISCUTIL_H_VERSION;
  *
  * Function    :  zalloc
  *
  *
  * Function    :  zalloc
  *
- * Description :  Malloc some memory and set it to '\0'.
+ * Description :  Returns allocated memory that is initialized
+ *                with zeros.
  *
  * Parameters  :
  *          1  :  size = Size of memory chunk to return.
  *
  *
  * Parameters  :
  *          1  :  size = Size of memory chunk to return.
  *
- * Returns     :  Pointer to newly malloc'd memory chunk.
+ * Returns     :  Pointer to newly alloc'd memory chunk.
  *
  *********************************************************************/
 void *zalloc(size_t size)
 {
    void * ret;
 
  *
  *********************************************************************/
 void *zalloc(size_t size)
 {
    void * ret;
 
+#ifdef HAVE_CALLOC
+   ret = calloc(1, size);
+#else
    if ((ret = (void *)malloc(size)) != NULL)
    {
       memset(ret, 0, size);
    }
    if ((ret = (void *)malloc(size)) != NULL)
    {
       memset(ret, 0, size);
    }
+#endif
 
    return(ret);
 
 
    return(ret);