gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Thu Oct 1 05:48:21 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/6eb2e36c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5c06f7f8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e6486e9d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1b31c06b (commit)
	from  https://github.com/Gnucash/gnucash/commit/630cf65f (commit)



commit 6eb2e36c2da69513dc2fb494fc59c22ded7d1be2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Sep 30 09:50:54 2020 +0800

    minor optimisations, g_list_prepend then g_list_sort separately
    
    if building a g_list incrementally, don't sort on each insertion.

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index e33856ed0..cdba3c20f 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3933,12 +3933,12 @@ xaccAccountFindOpenLots (const Account *acc,
             continue;
 
         /* Ok, this is a valid lot.  Add it to our list of lots */
-        if (sort_func)
-            retval = g_list_insert_sorted (retval, lot, sort_func);
-        else
-            retval = g_list_prepend (retval, lot);
+        retval = g_list_prepend (retval, lot);
     }
 
+    if (sort_func)
+        retval = g_list_sort (retval, sort_func);
+
     return retval;
 }
 
diff --git a/libgnucash/engine/gncOwner.c b/libgnucash/engine/gncOwner.c
index 03e938fd9..456fefdf8 100644
--- a/libgnucash/engine/gncOwner.c
+++ b/libgnucash/engine/gncOwner.c
@@ -1045,13 +1045,15 @@ gncOwnerSetLotLinkMemo (Transaction *ll_txn)
 
         title = g_strdup_printf ("%s %s", gncInvoiceGetTypeString (invoice), gncInvoiceGetID (invoice));
 
-        titles = g_list_insert_sorted (titles, title, (GCompareFunc)g_strcmp0);
+        titles = g_list_prepend (titles, title);
         splits = g_list_prepend (splits, split); // splits don't need to be sorted
     }
 
     if (!titles)
         return; // We didn't find document lots
 
+    titles = g_list_sort (titles, (GCompareFunc)g_strcmp0);
+
     // Create the memo as we'd want it to be
     new_memo = g_strconcat (memo_prefix, titles->data, NULL);
     for (titer = titles->next; titer; titer = titer->next)

commit 5c06f7f8c0245fffac95339d0984dbc4c212adfe
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Sep 30 09:50:13 2020 +0800

    deprecate xaccAccountCountSplits with include_children = TRUE
    
    where xaccAccountCountSplits is called including children, call
    gnc_account_and_descendants_empty intead

diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c
index 8c5463194..f4abff187 100644
--- a/gnucash/gnome-utils/gnc-tree-view-account.c
+++ b/gnucash/gnome-utils/gnc-tree-view-account.c
@@ -2046,7 +2046,7 @@ gnc_plugin_page_account_tree_filter_accounts (Account *account,
 
     if (!fd->show_unused)
     {
-        if (xaccAccountCountSplits(account, TRUE) == 0)
+        if (gnc_account_and_descendants_empty(account))
         {
             LEAVE(" hide: unused");
             return FALSE;
diff --git a/gnucash/gnome/dialog-find-account.c b/gnucash/gnome/dialog-find-account.c
index 971cfdcf1..b1da9fd34 100644
--- a/gnucash/gnome/dialog-find-account.c
+++ b/gnucash/gnome/dialog-find-account.c
@@ -189,7 +189,7 @@ fill_model (GtkTreeModel *model, Account *account)
 {
     GtkTreeIter   iter;
     gchar        *fullname = gnc_account_get_full_name (account);
-    gint          splits = xaccAccountCountSplits (account, TRUE);
+    gboolean      acc_empty = gnc_account_and_descendants_empty (account);
     gnc_numeric   total = xaccAccountGetBalanceInCurrency (account, NULL, TRUE);
 
     PINFO("Add to Store: Account '%s'", fullname);
@@ -200,7 +200,7 @@ fill_model (GtkTreeModel *model, Account *account)
                         ACC_FULL_NAME, fullname, ACCOUNT, account,
                         PLACE_HOLDER, (xaccAccountGetPlaceholder (account) == TRUE ? "emblem-default" : NULL),
                         HIDDEN, (xaccAccountGetHidden (account) == TRUE ? "emblem-default" : NULL),
-                        NOT_USED, (splits == 0 ? "emblem-default" : NULL),
+                        NOT_USED, (acc_empty ? "emblem-default" : NULL),
                         BAL_ZERO, (gnc_numeric_zero_p (total) == TRUE ? "emblem-default" : NULL),
                         TAX, (xaccAccountGetTaxRelated (account) == TRUE ? "emblem-default" : NULL), -1);
     g_free (fullname);

commit e6486e9d955ee2ee2e4db051b5f3724af84809c3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Sep 30 09:49:07 2020 +0800

    deprecate xaccAccountCountSplits with include_children = FALSE
    
    whereby xaccAccountCountSplits is called with with_children = FALSE,
    test xaccAccountGetSplitList against NULL.

diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c
index 2575eee7d..be630f279 100644
--- a/gnucash/gnome-utils/dialog-account.c
+++ b/gnucash/gnome-utils/dialog-account.c
@@ -1389,7 +1389,7 @@ gnc_account_window_create(GtkWindow *parent, AccountWindow *aw)
                          &aw->commodity_mode);
 
     // If the account has transactions, prevent changes by displaying a label and tooltip
-    if (xaccAccountCountSplits (aw_get_account (aw), FALSE) > 0)
+    if (xaccAccountGetSplitList (aw_get_account (aw)) != NULL)
     {
         const gchar *sec_name = gnc_commodity_get_printname (xaccAccountGetCommodity(aw_get_account (aw)));
         GtkWidget *label = gtk_label_new (sec_name);
@@ -1473,7 +1473,7 @@ gnc_account_window_create(GtkWindow *parent, AccountWindow *aw)
     //   immutable if gnucash depends on details that would be lost/missing
     //   if changing from/to such a type. At the time of this writing the
     //   immutable types are AR, AP and trading types.
-    if (xaccAccountCountSplits (aw_get_account (aw), FALSE) > 0)
+    if (xaccAccountGetSplitList (aw_get_account (aw)) != NULL)
     {
         GNCAccountType atype = xaccAccountGetType (aw_get_account (aw));
         compat_types = xaccAccountTypesCompatibleWith (atype);
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index 52a78455e..7d5352c24 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -1643,7 +1643,7 @@ gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPag
     }
 
     // If no transaction or children just delete it.
-    if (!(xaccAccountCountSplits (account, FALSE) ||
+    if (!(xaccAccountGetSplitList (account) != NULL ||
           gnc_account_n_children (account)))
     {
         do_delete_account (account, NULL, NULL, NULL);
diff --git a/libgnucash/engine/test/utest-Invoice.c b/libgnucash/engine/test/utest-Invoice.c
index 4ef8d10e7..1b979bbd3 100644
--- a/libgnucash/engine/test/utest-Invoice.c
+++ b/libgnucash/engine/test/utest-Invoice.c
@@ -175,6 +175,12 @@ test_invoice_post ( Fixture *fixture, gconstpointer pData )
     g_assert(!gncInvoiceIsPosted(fixture->invoice));
 }
 
+static gboolean account_has_one_split (const Account *acc)
+{
+    GList *splits = xaccAccountGetSplitList (acc);
+    return (splits && !(splits->next));
+}
+
 static void
 test_invoice_posted_trans ( Fixture *fixture, gconstpointer pData )
 {
@@ -183,8 +189,8 @@ test_invoice_posted_trans ( Fixture *fixture, gconstpointer pData )
     gnc_numeric total = gncInvoiceGetTotal(fixture->invoice);
     gnc_numeric acct_balance, acct2_balance;
 
-    g_assert (1 == xaccAccountCountSplits (fixture->account, FALSE));
-    g_assert (1 == xaccAccountCountSplits (fixture->account2, FALSE));
+    g_assert (account_has_one_split (fixture->account));
+    g_assert (account_has_one_split (fixture->account2));
 
     acct_balance = xaccAccountGetBalance(fixture->account);
     acct2_balance = xaccAccountGetBalance(fixture->account2);

commit 1b31c06b29aab4f5c0c1736b2ff1b59b125d15e9
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Sep 30 09:48:13 2020 +0800

    [Account.cpp] add gnc_account_and_descendants_empty (acc)
    
    and deprecate xaccAccountCountSplits

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index 0105c9487..e33856ed0 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3887,6 +3887,20 @@ xaccAccountCountSplits (const Account *acc, gboolean include_children)
     return nr;
 }
 
+gboolean gnc_account_and_descendants_empty (Account *acc)
+{
+    g_return_val_if_fail (GNC_IS_ACCOUNT (acc), FALSE);
+    if (xaccAccountGetSplitList (acc)) return FALSE;
+    auto empty = TRUE;
+    auto *children = gnc_account_get_children (acc);
+    for (auto *n = children; n && empty; n = n->next)
+    {
+        empty = gnc_account_and_descendants_empty ((Account*)n->data);
+    }
+    g_list_free (children);
+    return empty;
+}
+
 LotList *
 xaccAccountGetLotList (const Account *acc)
 {
diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h
index 9682b502b..2afe184d9 100644
--- a/libgnucash/engine/Account.h
+++ b/libgnucash/engine/Account.h
@@ -256,6 +256,12 @@ void gnc_book_set_root_account(QofBook *book, Account *root);
 
 /** @} */
 
+/*  Tests account and descendants -- if all have no splits then return TRUE.
+ *  Otherwise if any account or its descendants have split return FALSE.
+ */
+
+gboolean gnc_account_and_descendants_empty (Account *acc);
+
 /** Composes a translatable error message showing which account
  *  names clash with the current account separator. Can be called
  *  after gnc_account_list_name_violations to have a consistent
@@ -1020,7 +1026,9 @@ SplitList* xaccAccountGetSplitList (const Account *account);
 
 
 /** The xaccAccountCountSplits() routine returns the number of all
- *    the splits in the account.
+ *    the splits in the account. xaccAccountCountSplits is O(N). if
+ *    testing for emptiness, use xaccAccountGetSplitList != NULL.
+
  * @param acc the account for which to count the splits
  *
  * @param include_children also count splits in descendants (TRUE) or



Summary of changes:
 gnucash/gnome-utils/dialog-account.c         |  4 ++--
 gnucash/gnome-utils/gnc-tree-view-account.c  |  2 +-
 gnucash/gnome/dialog-find-account.c          |  4 ++--
 gnucash/gnome/gnc-plugin-page-account-tree.c |  2 +-
 libgnucash/engine/Account.cpp                | 22 ++++++++++++++++++----
 libgnucash/engine/Account.h                  | 10 +++++++++-
 libgnucash/engine/gncOwner.c                 |  4 +++-
 libgnucash/engine/test/utest-Invoice.c       | 10 ++++++++--
 8 files changed, 44 insertions(+), 14 deletions(-)



More information about the gnucash-changes mailing list