From bfba1d3602b20895956767c668e86390f16cb782 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Wed, 8 Aug 2018 21:40:29 +0300 Subject: 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 Change-Id: Icd990423a5e6048e76922668aab67422f4bc1867 --- libglusterfs/src/graph.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index 2a171f3b8dc..26dfc4e6b81 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -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; -- cgit