From faab3c6eab99623337eb0acb54e0a31c2e630147 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Tue, 23 Apr 2024 22:27:03 +0800 Subject: [PATCH] [engine.i] even faster gnc_get_match_commodity_splits gnc_get_match_commodity_splits needs to scan the account splitlists to find suitable splits upto end_date. We can stop scanning at end_date because the splitlists are sorted by date. --- bindings/engine.i | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bindings/engine.i b/bindings/engine.i index 0546363c686..4afd2226728 100644 --- a/bindings/engine.i +++ b/bindings/engine.i @@ -129,19 +129,20 @@ static const GncGUID * gncBudgetGetGUID(GncBudget *x) SplitsVec gnc_get_match_commodity_splits (AccountVec accounts, bool use_end_date, time64 end_date, gnc_commodity *comm, bool sort) { - auto match = [use_end_date, end_date, comm](const Split* s) -> bool + SplitsVec rv; + auto maybe_accumulate = [&rv, use_end_date, end_date, comm](auto s) -> bool { if (xaccSplitGetReconcile (s) == VREC) return false; auto trans{xaccSplitGetParent (s)}; - if (use_end_date && xaccTransGetDate(trans) > end_date) return false; + if (use_end_date && xaccTransGetDate(trans) > end_date) return true; auto txn_comm{xaccTransGetCurrency (trans)}; auto acc_comm{xaccAccountGetCommodity (xaccSplitGetAccount (s))}; - return (txn_comm != acc_comm) && (!comm || comm == txn_comm || comm == acc_comm); + if ((txn_comm != acc_comm) && (!comm || comm == txn_comm || comm == acc_comm)) + rv.push_back (const_cast(s)); + return false; }; - std::vector rv; - auto maybe_accumulate_split = [&rv, match](auto s){ if (match(s)) rv.push_back (s); }; - for (const auto acc : accounts) - gnc_account_foreach_split (acc, maybe_accumulate_split, true); + auto scan_account = [&](auto acc){ gnc_account_find_split (acc, maybe_accumulate, false); }; + std::for_each (accounts.begin(), accounts.end(), scan_account); if (sort) std::sort (rv.begin(), rv.end(), [](auto a, auto b){ return xaccSplitOrder (a, b) < 0; }); return rv;