mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[account.cpp] gnc_accounts_and_all_descendants converted from scm
much more efficient than guile algorithm, avoids numerous repeated GList<->SCM conversions, and traversals of account descendants.
This commit is contained in:
parent
07fbcc0e9e
commit
fae7ea02cd
@ -48,10 +48,14 @@ AccountList * gnc_account_get_descendants (const Account *account);
|
||||
%newobject gnc_account_get_descendants_sorted;
|
||||
AccountList * gnc_account_get_descendants_sorted (const Account *account);
|
||||
|
||||
%newobject gnc_accounts_and_all_descendants;
|
||||
AccountList * gnc_accounts_and_all_descendants (AccountList *accounts);
|
||||
|
||||
%ignore gnc_account_get_children;
|
||||
%ignore gnc_account_get_children_sorted;
|
||||
%ignore gnc_account_get_descendants;
|
||||
%ignore gnc_account_get_descendants_sorted;
|
||||
%ignore gnc_accounts_and_all_descendants;
|
||||
%include <Account.h>
|
||||
|
||||
%include <Transaction.h>
|
||||
|
@ -49,6 +49,7 @@ extern "C" {
|
||||
|
||||
#include <numeric>
|
||||
#include <map>
|
||||
#include <unordered_set>
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_ACCOUNT;
|
||||
|
||||
@ -6228,6 +6229,21 @@ gboolean xaccAccountRegister (void)
|
||||
return qof_object_register (&account_object_def);
|
||||
}
|
||||
|
||||
using AccountSet = std::unordered_set<Account*>;
|
||||
static void maybe_add_descendants (Account* acc, gpointer arg)
|
||||
{
|
||||
if (static_cast <AccountSet*> (arg)->insert (acc).second)
|
||||
g_list_foreach (GET_PRIVATE(acc)->children, (GFunc) maybe_add_descendants, arg);
|
||||
};
|
||||
|
||||
GList *
|
||||
gnc_accounts_and_all_descendants (GList *accounts)
|
||||
{
|
||||
AccountSet accset;
|
||||
g_list_foreach (accounts, (GFunc) maybe_add_descendants, &accset);
|
||||
return std::accumulate (accset.begin(), accset.end(), (GList*) nullptr, g_list_prepend);
|
||||
}
|
||||
|
||||
/* ======================= UNIT TESTING ACCESS =======================
|
||||
* The following functions are for unit testing use only.
|
||||
*/
|
||||
|
@ -1620,6 +1620,7 @@ void dxaccAccountSetQuoteTZ (Account *account, const char *tz);
|
||||
const char * dxaccAccountGetQuoteTZ (const Account *account);
|
||||
/** @} */
|
||||
|
||||
GList * gnc_accounts_and_all_descendants (GList *accounts);
|
||||
|
||||
/** @name Account parameter names
|
||||
@{
|
||||
|
Loading…
Reference in New Issue
Block a user