From 7674ea878e934a072c5f40eafc78f7886b24808c Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Wed, 8 Aug 2018 21:40:44 +0300 Subject: libglusterfs/src/dict.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible It doesn't make sense to calloc (allocate and clear) memory when the code right away fills that memory with data. It may be optimized by the compiler, or have a microscopic performance improvement. In some cases, also changed allocation size to be sizeof some struct or type instead of a pointer - easier to read. In some cases, removed redundant strlen() calls by saving the result into a variable. 1. Only done for the straightforward cases. There's room for improvement. 2. Please review carefully, especially for string allocation, with the terminating NULL string. Only compile-tested! updates: bz#1193929 Signed-off-by: Yaniv Kaul Change-Id: Iea9098b9ec0a82a866fbc5836514b1b317daefa1 --- libglusterfs/src/dict.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index a1052b676e2..eff217df7ad 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -443,7 +443,7 @@ dict_set_lk (dict_t *this, char *key, data_t *value, gf_boolean_t replace) key_free = 0; } else { - pair->key = (char *) GF_CALLOC (1, strlen (key) + 1, + pair->key = (char *) GF_MALLOC (strlen (key) + 1, gf_common_mt_char); if (!pair->key) { if (pair == &this->free_pair) { @@ -2203,7 +2203,7 @@ _dict_modify_flag (dict_t *this, char *key, int flag, int op) this->free_pair_in_use = _gf_true; } - pair->key = (char *)GF_CALLOC(1, strlen (key) + 1, + pair->key = (char *)GF_MALLOC(strlen (key) + 1, gf_common_mt_char); if (!pair->key) { gf_msg("dict", GF_LOG_ERROR, ENOMEM, -- cgit