libglusterfs/src/graph.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: Icd990423a5e6048e76922668aab67422f4bc1867
This commit is contained in:
Yaniv Kaul 2018-08-08 21:40:29 +03:00 committed by Niels de Vos
parent 443aa8e582
commit bfba1d3602

View File

@ -1178,8 +1178,7 @@ glusterfs_graph_attach (glusterfs_graph_t *orig_graph, char *path,
}
file_len = stbuf.st_size;
volfile_content = GF_CALLOC (file_len+1, sizeof (char),
gf_common_mt_char);
volfile_content = GF_MALLOC (file_len+1, gf_common_mt_char);
if (!volfile_content)
return -ENOMEM;