From 8cb8cf91df8a4902025d814b62b9332ad1b291c7 Mon Sep 17 00:00:00 2001 From: Chris Dunlap Date: Mon, 22 Sep 2014 13:22:48 -0700 Subject: Replace zed's use of malloc with calloc When zed allocates memory via malloc(), it typically follows that with a memset(). However, calloc() implementations can often perform optimizations when zeroing memory: https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc This commit replaces zed's use of malloc() with calloc(). Signed-off-by: Chris Dunlap Signed-off-by: Brian Behlendorf Closes #2736 --- cmd/zed/zed_strings.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'cmd/zed/zed_strings.c') diff --git a/cmd/zed/zed_strings.c b/cmd/zed/zed_strings.c index 9b55d0346..8e0f58079 100644 --- a/cmd/zed/zed_strings.c +++ b/cmd/zed/zed_strings.c @@ -82,11 +82,10 @@ zed_strings_create(void) { zed_strings_t *zsp; - zsp = malloc(sizeof (*zsp)); + zsp = calloc(1, sizeof (*zsp)); if (!zsp) return (NULL); - memset(zsp, 0, sizeof (*zsp)); avl_create(&zsp->tree, _zed_strings_node_compare, sizeof (zed_strings_node_t), offsetof(zed_strings_node_t, node)); @@ -131,11 +130,10 @@ zed_strings_add(zed_strings_t *zsp, const char *s) return (-1); } len = sizeof (zed_strings_node_t) + strlen(s) + 1; - np = malloc(len); + np = calloc(1, len); if (!np) return (-1); - memset(np, 0, len); assert((char *) np->string + strlen(s) < (char *) np + len); (void) strcpy(np->string, s); avl_add(&zsp->tree, np); -- cgit v1.2.3