[rtems commit] Optimize calloc()
Sebastian Huber
sebh at rtems.org
Thu Oct 4 08:51:33 UTC 2018
Module: rtems
Branch: master
Commit: 313f897f10fcf56ad21e7a07f7d70106dccbc188
Changeset: http://git.rtems.org/rtems/commit/?id=313f897f10fcf56ad21e7a07f7d70106dccbc188
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Sep 13 14:50:08 2018 +0200
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(-)
diff --git a/cpukit/libcsupport/src/calloc.c b/cpukit/libcsupport/src/calloc.c
index 20db533..78b08ab 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
More information about the vc
mailing list