summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:40:44 +0300
committerNiels de Vos <ndevos@redhat.com>2018-08-22 13:31:14 +0000
commit7674ea878e934a072c5f40eafc78f7886b24808c (patch)
tree8d7dc4ae7a63c7900b7b2d5a877c0d567345bcd1 /libglusterfs
parent54e5fae2bbea0086c7dd7951bb8776c3672fedf4 (diff)
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 <ykaul@redhat.com> Change-Id: Iea9098b9ec0a82a866fbc5836514b1b317daefa1
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/dict.c4
1 files changed, 2 insertions, 2 deletions
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,