From 358468d036b45f823aaeed1a7dcd2aa2e35bed4d Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Fri, 29 Mar 2019 17:39:36 +0000 Subject: [PATCH] Use a hash table to track transactions for associate dialog When generating the list of transactions to look at, a GList was used to keep a list of transactions already processed. Change this to use a hash table instead as it is quicker. --- gnucash/gnome/dialog-trans-assoc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gnucash/gnome/dialog-trans-assoc.c b/gnucash/gnome/dialog-trans-assoc.c index d29cdfa81c..8be4703175 100644 --- a/gnucash/gnome/dialog-trans-assoc.c +++ b/gnucash/gnome/dialog-trans-assoc.c @@ -43,7 +43,7 @@ #include "Account.h" #define DIALOG_ASSOC_CM_CLASS "dialog-trans-assoc" -#define GNC_PREFS_GROUP "dialogs.trans-assoc" +#define GNC_PREFS_GROUP "dialogs.trans-assoc" /** Enumeration for the tree-store */ enum GncAssocColumn {DATE_TRANS, DESC_TRANS, URI_U, AVAILABLE, URI_SPLIT, URI, URI_RELATIVE}; @@ -373,7 +373,8 @@ get_trans_info (AssocDialog *assoc_dialog) GList *accts, *ptr; GtkTreeModel *model; GtkTreeIter iter; - GList *splits, *trans_list = NULL; + GList *splits; + GHashTable *trans_hash = g_hash_table_new (g_direct_hash, g_direct_equal); /* Get list of Accounts */ accts = gnc_account_get_descendants_sorted (root); @@ -399,8 +400,8 @@ get_trans_info (AssocDialog *assoc_dialog) Transaction *trans = xaccSplitGetParent (split); const gchar *uri; - // Look for trans already in trans_list - if (g_list_find (trans_list, trans) != NULL) + // Look for trans already in trans_hash + if (g_hash_table_lookup (trans_hash, trans)) continue; // fix an earlier error when storing relative paths in version 3.3 @@ -433,7 +434,7 @@ get_trans_info (AssocDialog *assoc_dialog) g_free (uri_u); g_free (scheme); } - trans_list = g_list_prepend (trans_list, trans); // add trans to trans_list + g_hash_table_insert (trans_hash, trans, trans); // add trans to trans_hash } qof_query_destroy (query); g_list_free (splits); @@ -443,8 +444,8 @@ get_trans_info (AssocDialog *assoc_dialog) gtk_tree_view_set_model (GTK_TREE_VIEW(assoc_dialog->view), model); g_object_unref(G_OBJECT(model)); + g_hash_table_destroy (trans_hash); g_list_free (accts); - g_list_free (trans_list); } static void