From 27764908e6ce6d033fda6e55be2519f3bc81cc1c Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sun, 5 Feb 2023 21:08:19 +0100 Subject: [PATCH] Import matcher - remove a few redundant tests with GLists --- gnucash/import-export/import-main-matcher.c | 51 +++++++++------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 94182daa3c..3e348f3df2 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -837,7 +837,7 @@ static void gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *menuitem, GNCImportMainMatcher *info) { - ENTER("assign_transfer_account_to_selection_cb"); + ENTER(""); GtkTreeView *treeview = GTK_TREE_VIEW(info->view); GtkTreeModel *model = gtk_tree_view_get_model (treeview); @@ -849,40 +849,31 @@ gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *menuitem, DEBUG("Rows in selection = %i", gtk_tree_selection_count_selected_rows (selection)); - DEBUG("Entering loop over selection"); GList *refs = NULL; - if (gtk_tree_selection_count_selected_rows (selection) > 0) + for (GList *l = selected_rows; l; l = l->next) { - for (GList *l = selected_rows; l != NULL; l = l->next) - { - gchar *path_str = gtk_tree_path_to_string (l->data); - GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, l->data); - gchar *fullname; - DEBUG("passing first = %s", first ? "true" : "false"); - DEBUG("passing is_selection = %s", is_selection ? "true" : "false"); - DEBUG("passing path = %s", path_str); - g_free (path_str); - refs = g_list_prepend (refs, ref); - fullname = gnc_account_get_full_name (assigned_account); - DEBUG("passing account value = %s", fullname); - g_free (fullname); - gnc_gen_trans_assign_transfer_account (treeview, - &first, is_selection, l->data, - &assigned_account, info); - fullname = gnc_account_get_full_name (assigned_account); - DEBUG("returned value of account = %s", fullname); - DEBUG("returned value of first = %s", first ? "true" : "false"); - g_free (fullname); - if (assigned_account == NULL) - break; - - } + gchar *path_str = gtk_tree_path_to_string (l->data); + GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, l->data); + DEBUG("passing first = %s", first ? "true" : "false"); + DEBUG("passing is_selection = %s", is_selection ? "true" : "false"); + DEBUG("passing path = %s", path_str); + g_free (path_str); + refs = g_list_prepend (refs, ref); + gnc_gen_trans_assign_transfer_account (treeview, + &first, is_selection, l->data, + &assigned_account, info); + gchar *fullname = gnc_account_get_full_name (assigned_account); + DEBUG("returned value of account = %s", fullname); + DEBUG("returned value of first = %s", first ? "true" : "false"); + g_free (fullname); + if (!assigned_account) + break; } g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free); // now reselect the transaction rows. This is very slow if there are lots of transactions. - for (GList *l = refs; l != NULL; l = l->next) + for (GList *l = refs; l; l = l->next) { GtkTreePath *path = gtk_tree_row_reference_get_path (l->data); gtk_tree_selection_select_path (selection, path); @@ -1052,8 +1043,8 @@ static void gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info) { - g_return_if_fail (info != NULL); - ENTER("assign_transfer_account_to_selection_cb"); + ENTER(""); + g_return_if_fail (info); GtkTreeView *treeview = GTK_TREE_VIEW(info->view); GtkTreeModel *model = gtk_tree_view_get_model (treeview);