summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Bergmann <sebastian@php.net>2002-04-27 15:23:46 +0000
committerSebastian Bergmann <sebastian@php.net>2002-04-27 15:23:46 +0000
commit90bad130a9800ee785793c49d6bc77cf93f448ec (patch)
tree4596e4f0f7b4ac8628a9035f60ca16106c56fecb
parent2dee392e5bbbc1238edc4eaa27b28d501357314a (diff)
downloadphp-git-90bad130a9800ee785793c49d6bc77cf93f448ec.tar.gz
MFZE1: If the size-operands of memset are constants, the compiler can turn them into fast inline code. So, instead of using ecalloc, we use emalloc + memset in macro form now. emalloc will not return NULL, so the chosen macro form is safe. This is not true for malloc(3). An inline function accomodates our needs here. Suggested by: http://www.mail-archive.com/dev%40httpd.apache.org/msg02492.html (Sascha)
-rw-r--r--Zend/zend_alloc.c17
-rw-r--r--Zend/zend_alloc.h3
2 files changed, 1 insertions, 19 deletions
diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index b24e31c2a1..81ac7eafa1 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -248,23 +248,6 @@ ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
}
-ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
-{
- void *p;
- int final_size = size*nmemb;
-
- HANDLE_BLOCK_INTERRUPTIONS();
- p = _emalloc(final_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
- if (!p) {
- HANDLE_UNBLOCK_INTERRUPTIONS();
- return (void *) p;
- }
- memset(p, 0, final_size);
- HANDLE_UNBLOCK_INTERRUPTIONS();
- return p;
-}
-
-
ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
zend_mem_header *p;
diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h
index c89fbfd04a..76a5bf2e39 100644
--- a/Zend/zend_alloc.h
+++ b/Zend/zend_alloc.h
@@ -75,7 +75,6 @@ ZEND_API char *zend_strndup(const char *s, unsigned int length);
ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
-ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
@@ -94,7 +93,7 @@ ZEND_API int _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
/* Relay wrapper macros */
#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
-#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
+#define ecalloc_rel(nmemb, size) memset(_emalloc((nmemb)*(size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC), 0, (nmemb)*(size))
#define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
#define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)