From b3d1eafb5e58223ad8defa761b6b57ff718b6e8f Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 4 Jan 2012 13:57:24 +0300 Subject: [PATCH] Minor optimization of memory allocation for string copy. Signed-off-by: Andrew Borodin --- src/filemanager/cmd.c | 8 +++++--- src/filemanager/panelize.c | 10 +++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 0eba78544..3a7528b37 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -1468,7 +1468,6 @@ get_random_hint (int force) static int last_sec; static struct timeval tv; GIConv conv; - GString *buffer; /* Do not change hints more often than one minute */ gettimeofday (&tv, NULL); @@ -1501,10 +1500,13 @@ get_random_hint (int force) conv = str_crt_conv_from ("UTF-8"); if (conv != INVALID_CONV) { + GString *buffer; + buffer = g_string_new (""); if (str_convert (conv, &data[start], buffer) != ESTR_FAILURE) - result = g_strdup (buffer->str); - g_string_free (buffer, TRUE); + result = g_string_free (buffer, FALSE); + else + g_string_free (buffer, TRUE); str_close_conv (conv); } diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index a9c853841..fc05bdebe 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -590,7 +590,6 @@ load_panelize (void) gchar **profile_keys, **keys; gsize len; GIConv conv; - GString *buffer; conv = str_crt_conv_from ("UTF-8"); @@ -612,25 +611,22 @@ load_panelize (void) while (*profile_keys) { + GString *buffer; if (mc_global.utf8_display || conv == INVALID_CONV) - { buffer = g_string_new (*profile_keys); - } else { buffer = g_string_new (""); if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE) - { - g_string_free (buffer, TRUE); - buffer = g_string_new (*profile_keys); - } + g_string_assign (buffer, *profile_keys); } add2panelize (g_string_free (buffer, FALSE), mc_config_get_string (mc_main_config, panelize_section, *profile_keys, "")); profile_keys++; } + g_strfreev (keys); str_close_conv (conv); } -- 2.11.4.GIT