summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:40:57 +0300
committerNiels de Vos <ndevos@redhat.com>2018-08-22 18:07:54 +0000
commit37cb48e5919a2eac2525245ce7a8185e17f514f2 (patch)
tree7c67837b4d3f7d84850bcb355d45b9dcaf2f1058 /libglusterfs
parenta2112bd6fa2e4851cd982a691165f76f0c90d977 (diff)
libglusterfs/src/common-utils.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: I579f5b405bf410aac5ab0452231124d354f94ed1
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 06636a1fa85..e547ad929af 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -560,7 +560,7 @@ xldump_subvolumes (xlator_t *this, void *d)
for (subv = this->children; subv; subv = subv->next)
len += (strlen (subv->xlator->name) + 1);
- subvstr = GF_CALLOC (1, len, gf_common_mt_strdup);
+ subvstr = GF_MALLOC (len, gf_common_mt_strdup);
len = 0;
for (subv = this->children; subv; subv= subv->next)
@@ -5045,7 +5045,6 @@ gf_replace_old_iatt_in_dict (dict_t *xdata)
int ret;
struct old_iatt *o_iatt; /* old iatt structure */
struct iatt *c_iatt; /* current iatt */
- int32_t len = sizeof(struct old_iatt);
if (!xdata) {
return 0;
@@ -5056,14 +5055,15 @@ gf_replace_old_iatt_in_dict (dict_t *xdata)
return 0;
}
- o_iatt = GF_CALLOC (1, len, gf_common_mt_char);
+ o_iatt = GF_CALLOC (1, sizeof (struct old_iatt), gf_common_mt_char);
if (!o_iatt) {
return -1;
}
oldiatt_from_iatt (o_iatt, c_iatt);
- ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, o_iatt, len);
+ ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, o_iatt,
+ sizeof (struct old_iatt));
if (ret) {
GF_FREE (o_iatt);
}
@@ -5077,7 +5077,6 @@ gf_replace_new_iatt_in_dict (dict_t *xdata)
int ret;
struct old_iatt *o_iatt; /* old iatt structure */
struct iatt *c_iatt; /* new iatt */
- int32_t len = sizeof(struct iatt);
if (!xdata) {
return 0;
@@ -5088,14 +5087,15 @@ gf_replace_new_iatt_in_dict (dict_t *xdata)
return 0;
}
- c_iatt = GF_CALLOC (1, len, gf_common_mt_char);
+ c_iatt = GF_CALLOC (1, sizeof (struct iatt), gf_common_mt_char);
if (!c_iatt) {
return -1;
}
iatt_from_oldiatt (c_iatt, o_iatt);
- ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, c_iatt, len);
+ ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, c_iatt,
+ sizeof (struct iatt));
if (ret) {
GF_FREE (c_iatt);
}