gnucash stable: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sun Oct 27 14:14:18 EDT 2024


Updated	 via  https://github.com/Gnucash/gnucash/commit/35ecad8d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6d7f4ec4 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e2f5c74b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c02152b3 (commit)
	from  https://github.com/Gnucash/gnucash/commit/6cabb5d8 (commit)



commit 35ecad8d21d016e3c3db584b366a61aa582f18d4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Oct 27 14:21:13 2024 +0800

    [reports] change xaccAccountGetSplitList to xaccAccountGetSplits
    
    because the latter is more efficient. fewer doubly-link list traversals.

diff --git a/gnucash/import-export/qif-imp/qif-merge-groups.scm b/gnucash/import-export/qif-imp/qif-merge-groups.scm
index 9b90453dd6..d9b37e94b2 100644
--- a/gnucash/import-export/qif-imp/qif-merge-groups.scm
+++ b/gnucash/import-export/qif-imp/qif-merge-groups.scm
@@ -66,7 +66,7 @@
   ;; This procedure does all the work. We'll define it, then call it safely.
   (define (private-find)
     (cond
-     ((any (compose pair? xaccAccountGetSplitList) old-accounts)
+     ((any (compose positive? xaccAccountGetSplitsSize) old-accounts)
       ;; Get all the splits in the new tree, then iterate over them
       ;; trying to find matches in the old tree.  If there are
       ;; matches, push the splits' parent onto a list.
diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index 3b52bc90c0..e89c54e1e7 100644
--- a/gnucash/report/report-utilities.scm
+++ b/gnucash/report/report-utilities.scm
@@ -476,8 +476,8 @@
   (define (less? a b) (< (to-date a) (to-date b)))
 
   (let lp ((splits (if split->date
-                       (stable-sort! (xaccAccountGetSplitList acc) less?)
-                       (xaccAccountGetSplitList acc)))
+                       (sort (xaccAccountGetSplits acc) less?)
+                       (xaccAccountGetSplits acc)))
            (dates (sort dates <))
            (result '())
            (last-result nosplit->elt))
@@ -1242,7 +1242,7 @@
              (gnc-account-get-full-name acc)
              (gnc-commodity-get-mnemonic (xaccAccountGetCommodity acc))
              (xaccAccountGetTypeStr (xaccAccountGetType acc)))
-     (for-each (cut gnc:dump-split <> #f) (xaccAccountGetSplitList acc))
+     (for-each (cut gnc:dump-split <> #f) (xaccAccountGetSplits acc))
      (format #t "         Balance: ~a Cleared: ~a Reconciled: ~a\n"
              (gnc:monetary->string
               (gnc:make-gnc-monetary
@@ -1267,7 +1267,7 @@
                             (gnc-get-current-root-account))))
          (inv-txns (filter (lambda (t) (eqv? (xaccTransGetTxnType t) TXN-TYPE-INVOICE))
                            (map xaccSplitGetParent
-                                (append-map xaccAccountGetSplitList acc-APAR))))
+                                (append-map xaccAccountGetSplits acc-APAR))))
          (invoices (map gncInvoiceGetInvoiceFromTxn inv-txns)))
     (define (maybe-date time64)         ;handle INT-MAX differently
       (if (= 9223372036854775807 time64) "?" (qof-print-date time64)))
diff --git a/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm b/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
index f122b4a7f7..0d877081b6 100644
--- a/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
+++ b/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
@@ -104,7 +104,7 @@
 
 (define (make-split-list account split-filter-pred)
   (reverse (filter split-filter-pred
-                   (xaccAccountGetSplitList account))))
+                   (xaccAccountGetSplits account))))
 
 ;; returns a predicate that returns true only if a split is
 ;; between early-date and late-date
diff --git a/gnucash/report/reports/locale-specific/us/taxtxf.scm b/gnucash/report/reports/locale-specific/us/taxtxf.scm
index e479e00424..0a18a490cc 100644
--- a/gnucash/report/reports/locale-specific/us/taxtxf.scm
+++ b/gnucash/report/reports/locale-specific/us/taxtxf.scm
@@ -141,7 +141,7 @@
 (define after-tax-day (< tax-day today))
 
 (define (make-split-list account split-filter-pred)
-  (filter split-filter-pred (xaccAccountGetSplitList account)))
+  (filter split-filter-pred (xaccAccountGetSplits account)))
 
 ;; returns a predicate that returns true only if a split is
 ;; between early-date and late-date
diff --git a/gnucash/report/reports/standard/advanced-portfolio.scm b/gnucash/report/reports/standard/advanced-portfolio.scm
index 4e259d12f0..ade2711b0c 100644
--- a/gnucash/report/reports/standard/advanced-portfolio.scm
+++ b/gnucash/report/reports/standard/advanced-portfolio.scm
@@ -772,7 +772,7 @@ by preventing negative stock balances.<br/>")
                    )
                  )
                )
-             (xaccAccountGetSplitList current)
+             (xaccAccountGetSplits current)
              )
 
             ;; Look for income and expense transactions that don't have a split in the
@@ -832,7 +832,7 @@ by preventing negative stock balances.<br/>")
                       )
                     )
                   )
-                  (xaccAccountGetSplitList parent-account)
+                  (xaccAccountGetSplits parent-account)
                 )
               )
             )
diff --git a/gnucash/report/reports/standard/balance-forecast.scm b/gnucash/report/reports/standard/balance-forecast.scm
index 75f598ca11..6032ff07cd 100644
--- a/gnucash/report/reports/standard/balance-forecast.scm
+++ b/gnucash/report/reports/standard/balance-forecast.scm
@@ -193,7 +193,7 @@ date point, a projected minimum balance including scheduled transactions."))
       ;; accounts up to the report start date.
       (let* ((accounts-dates (map (compose xaccTransGetDate xaccSplitGetParent car)
                                   (filter pair?
-                                          (map xaccAccountGetSplitList accounts))))
+                                          (map xaccAccountGetSplits accounts))))
              (earliest (and (pair? accounts-dates) (apply min accounts-dates)))
              (sx-hash (if earliest
                           (gnc-sx-all-instantiate-cashflow-all earliest from-date)
diff --git a/gnucash/report/reports/standard/equity-statement.scm b/gnucash/report/reports/standard/equity-statement.scm
index 2d5354db92..51f1115323 100644
--- a/gnucash/report/reports/standard/equity-statement.scm
+++ b/gnucash/report/reports/standard/equity-statement.scm
@@ -175,7 +175,7 @@
                          (and (eq? direction 'out)
                               (negative? split-value))))
                 (total-flow 'add (xaccTransGetCurrency transaction) split-value))))
-        (xaccAccountGetSplitList target-account)))
+        (xaccAccountGetSplits target-account)))
      target-account-list)
     total-flow))
 
diff --git a/gnucash/report/reports/standard/test/test-transaction.scm b/gnucash/report/reports/standard/test/test-transaction.scm
index 69ea922bfb..2a0cdf5e47 100644
--- a/gnucash/report/reports/standard/test/test-transaction.scm
+++ b/gnucash/report/reports/standard/test/test-transaction.scm
@@ -232,7 +232,7 @@
     ;;                     (xaccSplitGetAmount s)
     ;;                     (xaccAccountGetName (xaccSplitGetAccount (xaccSplitGetOtherSplit s)))
     ;;                     ))
-    ;;           (xaccAccountGetSplitList bank))
+    ;;           (xaccAccountGetSplits bank))
 
     ;; Finally we can begin testing
     (test-begin "general options")

commit 6d7f4ec4c868738ec43048e3fb3cd9212013ce90
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Oct 27 14:19:49 2024 +0800

    [engine.i] expose xaccAccountGetSplits in bindings
    
    because xaccAccountGetSplitList will create GList, scan and build SCM
    reverse order, and scm_reverse.
    
    xaccAccountGetSplits scans the vector, builds the SCM list in reverse.

diff --git a/bindings/engine.i b/bindings/engine.i
index 0885066f4e..4b7adbafe7 100644
--- a/bindings/engine.i
+++ b/bindings/engine.i
@@ -322,6 +322,8 @@ Account * gnc_book_get_template_root(QofBook *book);
 %typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
 %typemap(freearg) GSList *key_path "g_slist_free_full ($1, g_free);"
 
+const SplitsVec& xaccAccountGetSplits (const Account*);
+
 QofBook* qof_book_new (void);
 void qof_book_options_delete (QofBook *book, GSList *key_path);
 void qof_book_set_option (QofBook *book, KvpValue *new_value, GSList *key_path);

commit e2f5c74bb478bff3d002b7469e63b91571b47008
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Oct 27 15:17:27 2024 +0800

    [engine.i] VECTORREF_HELPER_INOUT to handle SplitsVec&

diff --git a/bindings/engine.i b/bindings/engine.i
index c8dae2f043..0885066f4e 100644
--- a/bindings/engine.i
+++ b/bindings/engine.i
@@ -86,6 +86,7 @@ GLIST_HELPER_INOUT(PriceList, SWIGTYPE_p_GNCPrice);
 // TODO: free PriceList?
 GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity);
 VECTOR_HELPER_INOUT(SplitsVec, SWIGTYPE_p_Split, Split);
+VECTORREF_HELPER_INOUT(SplitsVec&, SWIGTYPE_p_Split, Split);
 VECTOR_HELPER_INOUT(AccountVec, SWIGTYPE_p_Account, Account);
 
 %typemap(newfree) char * "g_free($1);"
diff --git a/common/base-typemaps.i b/common/base-typemaps.i
index 23c2a6cd4b..2a878a0122 100644
--- a/common/base-typemaps.i
+++ b/common/base-typemaps.i
@@ -185,6 +185,15 @@ typedef char gchar;
 }
 %enddef
 
+
+%define VECTORREF_HELPER_INOUT(VectorType, ElemSwigType, ElemType)
+
+%typemap(out) VectorType {
+    auto accum = [](SCM acc, auto n){ return scm_cons(SWIG_NewPointerObj(n, ElemSwigType, 0), acc); };
+    $result = std::accumulate ($1->rbegin(), $1->rend(), SCM_EOL, accum);
+}
+%enddef
+
 #elif defined(SWIGPYTHON) /* Typemaps for Python */
 
 %import "glib.h"

commit c02152b34ac5aa3cd2e67d200ac11eae53184444
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Oct 27 15:16:48 2024 +0800

    [Account.hpp] xaccAccountGetSplits returns a reference to vector

diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index d3f547359d..afcb769799 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -3881,10 +3881,11 @@ xaccAccountGetNoclosingBalanceChangeInCurrencyForPeriod (Account *acc, time64 t1
 /********************************************************************\
 \********************************************************************/
 
-const SplitsVec
+const SplitsVec&
 xaccAccountGetSplits (const Account *account)
 {
-    g_return_val_if_fail (GNC_IS_ACCOUNT(account), SplitsVec{});
+    static const SplitsVec empty;
+    g_return_val_if_fail (GNC_IS_ACCOUNT(account), empty);
     return GET_PRIVATE(account)->splits;
 }
 
diff --git a/libgnucash/engine/Account.hpp b/libgnucash/engine/Account.hpp
index 3a3c51addf..89649acfc4 100644
--- a/libgnucash/engine/Account.hpp
+++ b/libgnucash/engine/Account.hpp
@@ -40,7 +40,7 @@
 using SplitsVec = std::vector<Split*>;
 using AccountVec = std::vector<Account*>;
 
-const SplitsVec xaccAccountGetSplits (const Account*);
+const SplitsVec& xaccAccountGetSplits (const Account*);
 
 void gnc_account_foreach_descendant (const Account *, std::function<void(Account*)> func);
 
diff --git a/libgnucash/engine/mocks/gmock-Account.cpp b/libgnucash/engine/mocks/gmock-Account.cpp
index 3250a2c1b4..c59e82b3c5 100644
--- a/libgnucash/engine/mocks/gmock-Account.cpp
+++ b/libgnucash/engine/mocks/gmock-Account.cpp
@@ -76,13 +76,14 @@ xaccAccountGetSplitList (const Account *account)
     return mockaccount ? mockaccount->xaccAccountGetSplitList() : nullptr;
 }
 
-const std::vector<Split*>
+const std::vector<Split*>&
 xaccAccountGetSplits (const Account *account)
 {
     SCOPED_TRACE("");
     auto mockaccount = gnc_mockaccount(account);
+    static const SplitsVec empty;
     if (!mockaccount)
-        return {};
+        return empty;
     return mockaccount->xaccAccountGetSplits();
 }
 
diff --git a/libgnucash/engine/mocks/gmock-Account.h b/libgnucash/engine/mocks/gmock-Account.h
index 97860fdc5e..a5cc8f006c 100644
--- a/libgnucash/engine/mocks/gmock-Account.h
+++ b/libgnucash/engine/mocks/gmock-Account.h
@@ -46,7 +46,7 @@ public:
     MOCK_CONST_METHOD0(get_commodity, gnc_commodity*());
     MOCK_CONST_METHOD2(for_each_transaction, gint(TransactionCallback, void*));
     MOCK_CONST_METHOD0(xaccAccountGetSplitList, SplitList*());
-    MOCK_CONST_METHOD0(xaccAccountGetSplits, std::vector<Split*>());
+    MOCK_CONST_METHOD0(xaccAccountGetSplits, std::vector<Split*>&());
     MOCK_METHOD2(find_account, Account *(const char*, const char*));
     MOCK_METHOD3(add_account, void(const char*, const char*, Account*));
     MOCK_METHOD1(find_account_bayes, Account *(std::vector<const char*>&));



Summary of changes:
 bindings/engine.i                                         | 3 +++
 common/base-typemaps.i                                    | 9 +++++++++
 gnucash/import-export/qif-imp/qif-merge-groups.scm        | 2 +-
 gnucash/report/report-utilities.scm                       | 8 ++++----
 gnucash/report/reports/locale-specific/de_DE/taxtxf.scm   | 2 +-
 gnucash/report/reports/locale-specific/us/taxtxf.scm      | 2 +-
 gnucash/report/reports/standard/advanced-portfolio.scm    | 4 ++--
 gnucash/report/reports/standard/balance-forecast.scm      | 2 +-
 gnucash/report/reports/standard/equity-statement.scm      | 2 +-
 gnucash/report/reports/standard/test/test-transaction.scm | 2 +-
 libgnucash/engine/Account.cpp                             | 5 +++--
 libgnucash/engine/Account.hpp                             | 2 +-
 libgnucash/engine/mocks/gmock-Account.cpp                 | 5 +++--
 libgnucash/engine/mocks/gmock-Account.h                   | 2 +-
 14 files changed, 32 insertions(+), 18 deletions(-)



More information about the gnucash-changes mailing list