From: Fabian Keil <fk@fabiankeil.de>
Date: Mon, 29 May 2017 10:05:46 +0000 (+0000)
Subject: Let zalloc() use calloc() if it's available
X-Git-Tag: v_3_0_27~150
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/faq/@default-cgi@/developer-manual/static/documentation.html?a=commitdiff_plain;h=2f180f0a2a126bd3da1b5bf3466ee1ed247cf91e;p=privoxy.git

Let zalloc() use calloc() if it's available

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
---

diff --git a/configure.in b/configure.in
index f905bcf1..b75d90ad 100644
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,6 @@
 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/
@@ -32,7 +32,7 @@ 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
@@ -782,6 +782,7 @@ AC_CHECK_FUNCS([ \
  access \
  arc4random \
  atexit \
+ calloc \
  getcwd \
  gethostbyaddr \
  gethostbyaddr_r \
diff --git a/miscutil.c b/miscutil.c
index 4a9b88f3..ea2c3aae 100644
--- a/miscutil.c
+++ b/miscutil.c
@@ -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 $
@@ -71,22 +71,27 @@ const char miscutil_h_rcs[] = MISCUTIL_H_VERSION;
  *
  * 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.
  *
- * Returns     :  Pointer to newly malloc'd memory chunk.
+ * Returns     :  Pointer to newly alloc'd memory chunk.
  *
  *********************************************************************/
 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);
    }
+#endif
 
    return(ret);