[PATCH 09/25] Optimize calloc()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 14 13:18:37 UTC 2018


Use return value of memset() to enable tail call optimizations.
---
 cpukit/libcsupport/src/calloc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

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




More information about the devel mailing list