about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-12-19 19:25:58 +0100
committerMichael Vetter <jubalh@iodoru.org>2019-12-19 19:25:58 +0100
commit1f809e5210c4cfa152418def23791723c949d672 (patch)
treea04b3590e9d712780695b58aec29e568cbfcd487 /src
parent808850c6f5c85b0e173e922b9979ca3a09b4dc31 (diff)
downloadprofani-tty-1f809e5210c4cfa152418def23791723c949d672.tar.gz
Refactor _cmd_set_boolean_preference
Only compute string if necessary.
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_funcs.c19
1 files 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