Skip to content

Commit

Permalink
[SchedXaction.cpp] use c++ algo
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Jun 1, 2024
1 parent 55592ef commit 7dc2e2e
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions libgnucash/engine/SchedXaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "qof.h"

#include "Account.h"
#include "Account.hpp"
#include "SX-book.h"
#include "SX-book-p.h"
#include "SX-ttinfo.h"
Expand All @@ -40,6 +41,8 @@
#include "engine-helpers.h"
#include "qofinstance-p.h"

#include <unordered_set>

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.engine.sx"

Expand Down Expand Up @@ -416,46 +419,20 @@ xaccSchedXactionMalloc(QofBook *book)
return sx;
}

static void
sxprivTransMapDelete( gpointer data, gpointer user_data )
{
Transaction *t = (Transaction *) data;
xaccTransBeginEdit( t );
xaccTransDestroy( t );
xaccTransCommitEdit( t );
return;
}

static void
delete_template_trans(SchedXaction *sx)
{
GList *templ_acct_splits, *curr_split_listref;
Split *curr_split;
Transaction *split_trans;
GList *templ_acct_transactions = NULL;

templ_acct_splits
= xaccAccountGetSplitList(sx->template_acct);

for (curr_split_listref = templ_acct_splits;
curr_split_listref;
curr_split_listref = curr_split_listref->next)
{
curr_split = (Split *) curr_split_listref->data;
split_trans = xaccSplitGetParent(curr_split);
if (! (g_list_find(templ_acct_transactions, split_trans)))
{
templ_acct_transactions
= g_list_prepend(templ_acct_transactions, split_trans);
}
}

g_list_foreach(templ_acct_transactions,
sxprivTransMapDelete,
NULL);

g_list_free (templ_acct_splits);
g_list_free (templ_acct_transactions);
std::unordered_set<Transaction*> txns;
auto& splits{xaccAccountGetSplits (sx->template_acct)};
std::for_each (splits.begin(), splits.end(),
[&txns](auto s){ txns.insert (xaccSplitGetParent (s)); });
std::for_each (txns.begin(), txns.end(),
[](auto t)
{
xaccTransBeginEdit (t);
xaccTransDestroy (t);
xaccTransCommitEdit (t);
});
return;
}

Expand Down

0 comments on commit 7dc2e2e

Please sign in to comment.