From 2b95d2c0be20a62279bbfebc17457004aca0988f Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Wed, 8 Aug 2018 21:42:45 +0300 Subject: cli/src/cli-cmd-parser.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: Ic1531afbf614823628cc8d70bae782d4db7ec033 --- cli/src/cli-cmd-parser.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index d0f8a20cee0..9ec4d312e6f 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2656,7 +2656,7 @@ config_parse (const char **words, int wordcount, dict_t *dict, goto out; GF_FREE (append_str); - append_str = GF_CALLOC (1, 300, cli_mt_append_str); + append_str = GF_MALLOC (300, cli_mt_append_str); if (!append_str) { ret = -1; goto out; @@ -2676,7 +2676,7 @@ config_parse (const char **words, int wordcount, dict_t *dict, goto out; } GF_FREE (append_str); - append_str = GF_CALLOC (1, 300, cli_mt_append_str); + append_str = GF_MALLOC (300, cli_mt_append_str); if (!append_str) { ret = -1; goto out; @@ -3739,7 +3739,8 @@ extract_hostname_path_from_token (const char *tmp_words, char **hostname, goto out; } else { str_len = strlen (delimiter + 1) + 1; - *path = GF_MALLOC (str_len, gf_common_mt_char); + *path = GF_MALLOC (str_len, + gf_common_mt_char); if (!*path) { ret = -1; goto out; @@ -4184,7 +4185,7 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words, int32_t desc_len = 0; int len; - desc = GF_CALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, sizeof(char), + desc = GF_MALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, gf_common_mt_char); if (!desc) { ret = -1; -- cgit