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.
This commit is contained in:
Robert Fewell 2019-03-29 17:39:36 +00:00
parent 2cb34d4874
commit 358468d036

View File

@ -373,7 +373,8 @@ get_trans_info (AssocDialog *assoc_dialog)
GList *accts, *ptr; GList *accts, *ptr;
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter; 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 */ /* Get list of Accounts */
accts = gnc_account_get_descendants_sorted (root); accts = gnc_account_get_descendants_sorted (root);
@ -399,8 +400,8 @@ get_trans_info (AssocDialog *assoc_dialog)
Transaction *trans = xaccSplitGetParent (split); Transaction *trans = xaccSplitGetParent (split);
const gchar *uri; const gchar *uri;
// Look for trans already in trans_list // Look for trans already in trans_hash
if (g_list_find (trans_list, trans) != NULL) if (g_hash_table_lookup (trans_hash, trans))
continue; continue;
// fix an earlier error when storing relative paths in version 3.3 // 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 (uri_u);
g_free (scheme); 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); qof_query_destroy (query);
g_list_free (splits); 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); gtk_tree_view_set_model (GTK_TREE_VIEW(assoc_dialog->view), model);
g_object_unref(G_OBJECT(model)); g_object_unref(G_OBJECT(model));
g_hash_table_destroy (trans_hash);
g_list_free (accts); g_list_free (accts);
g_list_free (trans_list);
} }
static void static void