gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sun Apr 14 11:30:26 EDT 2024
Updated via https://github.com/Gnucash/gnucash/commit/c1ee59c3 (commit)
via https://github.com/Gnucash/gnucash/commit/f08e0f5b (commit)
from https://github.com/Gnucash/gnucash/commit/a272a033 (commit)
commit c1ee59c39bf5287f30dc2ef489b5f4b71db66029
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Apr 14 16:17:42 2024 +0800
[Account.h] size_t xaccAccountGetSplitsSize returns g_list_length (splits)
which is easily replaced with vector.size()
diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp
index b456da0563..052bc7e241 100644
--- a/libgnucash/engine/Account.cpp
+++ b/libgnucash/engine/Account.cpp
@@ -4048,6 +4048,11 @@ xaccAccountGetSplitList (const Account *acc)
return GET_PRIVATE(acc)->splits;
}
+size_t
+xaccAccountGetSplitsSize (const Account *account)
+{
+ return GNC_IS_ACCOUNT(account) ? g_list_length (GET_PRIVATE(account)->splits) : 0;
+}
gboolean gnc_account_and_descendants_empty (Account *acc)
{
diff --git a/libgnucash/engine/Account.h b/libgnucash/engine/Account.h
index daac6b52af..83fa8d3901 100644
--- a/libgnucash/engine/Account.h
+++ b/libgnucash/engine/Account.h
@@ -1060,6 +1060,8 @@ typedef enum
*/
SplitList* xaccAccountGetSplitList (const Account *account);
+ size_t xaccAccountGetSplitsSize (const Account *account);
+
/** The xaccAccountMoveAllSplits() routine reassigns each of the splits
* in accfrom to accto. */
void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);
commit f08e0f5b61a70a8d280f513b71c50c8c70c2476a
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Apr 14 23:07:04 2024 +0800
[policy.cpp] rewrite to avoid goto
diff --git a/libgnucash/engine/policy.cpp b/libgnucash/engine/policy.cpp
index e8039749b1..ce89264219 100644
--- a/libgnucash/engine/policy.cpp
+++ b/libgnucash/engine/policy.cpp
@@ -67,7 +67,6 @@ static Split *
DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
{
Split *split;
- SplitList *node;
gnc_commodity *common_currency;
gboolean want_positive;
gnc_numeric baln;
@@ -101,51 +100,38 @@ DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
* hasn't been assigned to a lot. Return that split.
* Make use of the fact that the splits in an account are
* already in date order; so we don't have to sort. */
- node = xaccAccountGetSplitList (lot_account);
- if (reverse)
- {
- node = g_list_last (node);
- }
- while (node)
+ auto splits = xaccAccountGetSplitList (lot_account);
+
+ Split *rv = nullptr;
+
+ for (auto node = reverse ? g_list_last (splits) : splits; !rv && node;
+ node = reverse ? node->prev : node->next)
{
- gboolean is_match;
- gboolean is_positive;
- time64 this_time;
split = GNC_SPLIT(node->data);
- if (split->lot) goto donext;
+ if (split->lot)
+ continue;
/* Skip it if it's too early */
- this_time = xaccTransRetDatePosted ( xaccSplitGetParent (split));
- if (this_time < open_time)
+ if (xaccTransRetDatePosted (xaccSplitGetParent (split)) < open_time)
{
if (reverse)
/* Going backwards, no point in looking further */
break;
- goto donext;
+ continue;
}
/* Allow equiv currencies */
- is_match = gnc_commodity_equiv (common_currency,
- split->parent->common_currency);
- if (FALSE == is_match) goto donext;
+ if (!gnc_commodity_equiv (common_currency, split->parent->common_currency))
+ continue;
/* Disallow zero-amount splits in general. */
- if (gnc_numeric_zero_p(split->amount)) goto donext;
+ if (gnc_numeric_zero_p(split->amount))
+ continue;
- is_positive = gnc_numeric_positive_p (split->amount);
- if ((want_positive && is_positive) ||
- ((!want_positive) && (!is_positive))) return split;
-donext:
- if (reverse)
- {
- node = node->prev;
- }
- else
- {
- node = node->next;
- }
+ if (want_positive == gnc_numeric_positive_p (split->amount))
+ rv = split;
}
- return nullptr;
+ return rv;
}
/* ============================================================== */
Summary of changes:
libgnucash/engine/Account.cpp | 5 +++++
libgnucash/engine/Account.h | 2 ++
libgnucash/engine/policy.cpp | 48 +++++++++++++++----------------------------
3 files changed, 24 insertions(+), 31 deletions(-)
More information about the gnucash-changes
mailing list