From 1f809e5210c4cfa152418def23791723c949d672 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 19 Dec 2019 19:25:58 +0100 Subject: [PATCH] Refactor _cmd_set_boolean_preference Only compute string if necessary. --- src/command/cmd_funcs.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index aa1f21c3..80480c98 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8105,26 +8105,27 @@ static void _cmd_set_boolean_preference(gchar *arg, const char *const command, const char *const display, preference_t pref) { - GString *enabled = g_string_new(display); - g_string_append(enabled, " enabled."); - - GString *disabled = g_string_new(display); - g_string_append(disabled, " disabled."); - if (arg == NULL) { cons_bad_cmd_usage(command); } else if (strcmp(arg, "on") == 0) { + GString *enabled = g_string_new(display); + g_string_append(enabled, " enabled."); + cons_show(enabled->str); prefs_set_boolean(pref, TRUE); + + g_string_free(enabled, TRUE); } else if (strcmp(arg, "off") == 0) { + GString *disabled = g_string_new(display); + g_string_append(disabled, " disabled."); + cons_show(disabled->str); prefs_set_boolean(pref, FALSE); + + g_string_free(disabled, TRUE); } else { cons_bad_cmd_usage(command); } - - g_string_free(enabled, TRUE); - g_string_free(disabled, TRUE); } gboolean