[gnome-commander/get_rid_of_xml] Do some optimization work on set_gsettings_string_array_from_glist



commit 6962eb098a16a5ddde567bf91638109baf503061
Author: Uwe Scholz <u scholz83 gmx de>
Date:   Thu Dec 20 17:20:45 2018 +0100

    Do some optimization work on set_gsettings_string_array_from_glist

 src/gnome-cmd-data.cc | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index aa28858f..3694660e 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -2400,32 +2400,27 @@ gboolean GnomeCmdData::set_gsettings_string_array_from_glist (GSettings *setting
 {
     gboolean rv = true;
 
-    if (strings == NULL)
+    if (strings == nullptr)
     {
-        rv = g_settings_set_strv(settings_given, key, NULL);
+        rv = g_settings_set_strv(settings_given, key, nullptr);
     }
     else
     {
         guint ii;
-        guint numberOfStrings = g_list_length (strings);
+        auto numberOfStrings = g_list_length (strings);
         gchar** str_array;
-        str_array = (gchar**) g_malloc ((numberOfStrings + 1) * sizeof(char*));
+        str_array = new char * [numberOfStrings + 1];
 
         // Build up a NULL terminated char array for storage in GSettings
         for (ii = 0; strings; strings = strings->next, ++ii)
         {
-            str_array[ii] = g_strdup((const gchar*) strings->data);
+            str_array[ii] = (gchar*) strings->data;
         }
-        str_array[ii] = NULL;
+        str_array[ii] = nullptr;
 
         rv = g_settings_set_strv(settings_given, key, str_array);
 
-        // Free the char array
-        for (ii = 0; ii < (numberOfStrings + 1); ii++)
-        {
-            g_free(str_array[ii]);
-        }
-        g_free(str_array);
+        delete[](str_array);
     }
     return rv;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]