[Xfce4-commits] <xfce-utils:completion> Improve performances in xfrun_history_save.

Jérôme Guelfucci noreply at xfce.org
Fri Nov 5 18:26:03 CET 2010


Updating branch refs/heads/completion
         to 0ee3ddb1e3f5af76b7e7bddea818431dd2fb28dc (commit)
       from 28fe32f9f524f135f2efb7ce7e86945f33f6bfec (commit)

commit 0ee3ddb1e3f5af76b7e7bddea818431dd2fb28dc
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Fri Nov 5 18:24:57 2010 +0100

    Improve performances in xfrun_history_save.
    
    Use a GString instead of g_strconcat.

 xfrun/xfrun-history.c |   27 ++++++++++++---------------
 1 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/xfrun/xfrun-history.c b/xfrun/xfrun-history.c
index f438b10..27031ce 100644
--- a/xfrun/xfrun-history.c
+++ b/xfrun/xfrun-history.c
@@ -180,36 +180,33 @@ static GList
 static void
 xfrun_history_save (GList *list)
 {
-  GError *error;
-  gchar  *history_file;
-  gchar  *contents;
-  GList  *l;
+  GError  *error;
+  GString *string;
+  gchar   *history_file;
+  gchar   *contents;
+  GList   *l;
 
   if (list == NULL)
     return;
 
   error = NULL;
-  contents = g_strdup ("");
+  string = g_string_sized_new (512);
   history_file =
     xfce_resource_lookup (XFCE_RESOURCE_CACHE, "xfce4/xfrun4/history");
 
   for (l = list; l != NULL; l = g_list_next (l))
     {
       XfrunHistoryItem *item;
-      gchar            *tmp;
 
       item = (XfrunHistoryItem *) l->data;
 
-      tmp = g_strconcat (contents,
-                         item->in_terminal ? "1" : "0",
-                         ":",
-                         item->command,
-                         "\n", NULL);
-
-      g_free (contents);
-      contents = tmp;
+      g_string_append (string, item->in_terminal ? "1:" : "0:");
+      g_string_append (string, item->command);
+      g_string_append (string, "\n");
     }
 
+  contents = string->str;
+
   if (!g_file_set_contents (history_file, contents, strlen (contents), &error))
     {
       xfce_dialog_show_error (NULL, error,
@@ -218,7 +215,7 @@ xfrun_history_save (GList *list)
       g_error_free (error);
     }
 
-  g_free (contents);
+  g_string_free (string, TRUE);
   g_free (history_file);
 }
 



More information about the Xfce4-commits mailing list