From 313f897f10fcf56ad21e7a07f7d70106dccbc188 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 13 Sep 2018 14:50:08 +0200 Subject: Optimize calloc() Use return value of memset() to enable tail call optimizations. --- cpukit/libcsupport/src/calloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'cpukit/libcsupport/src/calloc.c') diff --git a/cpukit/libcsupport/src/calloc.c b/cpukit/libcsupport/src/calloc.c index 20db533786..78b08ab5a5 100644 --- a/cpukit/libcsupport/src/calloc.c +++ b/cpukit/libcsupport/src/calloc.c @@ -28,15 +28,16 @@ void *calloc( size_t elsize ) { - char *cptr; + void *cptr; size_t length; length = nelem * elsize; cptr = malloc( length ); RTEMS_OBFUSCATE_VARIABLE( cptr ); - if ( cptr ) - memset( cptr, '\0', length ); + if ( RTEMS_PREDICT_FALSE( cptr == NULL ) ) { + return cptr; + } - return cptr; + return memset( cptr, 0, length ); } #endif -- cgit v1.2.3