From 6790430ee8ba02b1209a9f33a7ba1ffb847072c2 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Tue, 18 Jun 2024 08:24:37 +0800 Subject: [PATCH] [split-register-control.cpp] use c++ algo --- .../ledger-core/split-register-control.cpp | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/gnucash/register/ledger-core/split-register-control.cpp b/gnucash/register/ledger-core/split-register-control.cpp index c0a8c6519f..1c38c7d3fe 100644 --- a/gnucash/register/ledger-core/split-register-control.cpp +++ b/gnucash/register/ledger-core/split-register-control.cpp @@ -26,6 +26,7 @@ #include #include +#include "Account.hpp" #include "Scrub.h" #include "combocell.h" #include "gnc-component-manager.h" @@ -668,23 +669,14 @@ static Split * gnc_find_split_in_account_by_memo (Account *account, const char *memo, gboolean unit_price) { - if (account == NULL) return NULL; + if (account == nullptr) return nullptr; - Split *rv = nullptr; - auto splits = xaccAccountGetSplitList (account); - for (auto slp = g_list_last (splits); !rv && slp; slp = slp->prev) - { - auto split = GNC_SPLIT(slp->data); - Transaction *trans = xaccSplitGetParent (split); + const auto& splits = xaccAccountGetSplits (account); + for (auto it = splits.rbegin(); it != splits.rend(); it++) + if (auto split = gnc_find_split_in_trans_by_memo (xaccSplitGetParent (*it), memo, unit_price)) + return split; - split = gnc_find_split_in_trans_by_memo (trans, memo, unit_price); - - if (split) - rv = split; - } - - g_list_free (splits); - return rv; + return nullptr; } static Split *