r22074 - gnucash/trunk/src/libqof/qof - Replace g_list_append by g_list_prepend to increase performance.

Christian Stimming cstim at code.gnucash.org
Sun Mar 11 17:55:54 EDT 2012


Author: cstim
Date: 2012-03-11 17:55:53 -0400 (Sun, 11 Mar 2012)
New Revision: 22074
Trac: http://svn.gnucash.org/trac/changeset/22074

Modified:
   gnucash/trunk/src/libqof/qof/qofobject.c
Log:
Replace g_list_append by g_list_prepend to increase performance.

To my surprise, this apparently also fixes a memory leak, but I don't know why.

Modified: gnucash/trunk/src/libqof/qof/qofobject.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofobject.c	2012-03-09 00:07:13 UTC (rev 22073)
+++ gnucash/trunk/src/libqof/qof/qofobject.c	2012-03-11 21:55:53 UTC (rev 22074)
@@ -226,10 +226,10 @@
 }
 
 static void
-do_append (QofInstance *qof_p, gpointer list_p)
+do_prepend (QofInstance *qof_p, gpointer list_p)
 {
     GList **list = list_p;
-    *list = g_list_append(*list, qof_p);
+    *list = g_list_prepend(*list, qof_p);
 }
 
 void
@@ -238,7 +238,7 @@
     GList *list = NULL;
     GList *iter;
 
-    qof_object_foreach(type_name, book, do_append, &list);
+    qof_object_foreach(type_name, book, do_prepend, &list);
 
     list = g_list_sort(list, qof_instance_guid_compare);
 
@@ -248,6 +248,13 @@
     }
 
     g_list_free(list);
+
+    // FIXME: Apparently this is a memory leak, as this g_list_free doesn't
+    // free all of the allocated memory of g_list_append in do_append(). Why?!?
+    // Does g_list_sort have special side-effects on the memory of the list?
+    // Subsequently, I've changed the g_list_append into g_list_prepend, but
+    // solely for performance reasons. To my surprise, this also makes the
+    // dubious memory leak go away. But again why?!?
 }
 
 const char *



More information about the gnucash-changes mailing list