From 35776f481c02caa700369db0e884bd9f7c7d3c0e Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 18 Jan 2007 12:54:18 +0000 Subject: Don't always zero memory in malloc(). This saves around 2us on a full-length PKB allocation. --- src/include/stdlib.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/include') diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 2b6471e1c..39ad831fc 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -8,6 +8,8 @@ extern void free ( void *ptr ); extern int system ( const char *command ); extern long int random ( void ); +extern void * _calloc ( size_t len ); + /** * Allocate cleared memory * @@ -17,12 +19,12 @@ extern long int random ( void ); * * Allocate memory as per malloc(), and zero it. * - * Note that malloc() and calloc() are identical, in the interests of - * reducing code size. Callers should not, however, rely on malloc() - * clearing memory, since this behaviour may change in future. + * This is implemented as a static inline, with the body of the + * function in _calloc(), since in most cases @c nmemb will be 1 and + * doing the multiply is just wasteful. */ static inline void * calloc ( size_t nmemb, size_t size ) { - return malloc ( nmemb * size ); + return _calloc ( nmemb * size ); } #endif /* STDLIB_H */ -- cgit v1.2.3-55-g7522