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 <ykaul@redhat.com>

Change-Id: Ic1531afbf614823628cc8d70bae782d4db7ec033
This commit is contained in:
Yaniv Kaul 2018-08-08 21:42:45 +03:00 committed by Sanju Rakonde
parent 3ee5f7ee34
commit 2b95d2c0be

View File

@ -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;