mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[Scrub.cpp] don't create intermediate GHashTable and GList
use unordered_set instead
This commit is contained in:
parent
a84189b79d
commit
f65f877098
@ -44,6 +44,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "AccountP.hpp"
|
#include "AccountP.hpp"
|
||||||
@ -90,22 +91,18 @@ gnc_get_ongoing_scrub (void)
|
|||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
|
||||||
static void add_transactions (const Account *account, GHashTable **ht)
|
using TransSet = std::unordered_set<Transaction*>;
|
||||||
{
|
|
||||||
for (auto s : xaccAccountGetSplits (account))
|
|
||||||
g_hash_table_add (*ht, xaccSplitGetParent (s));
|
|
||||||
}
|
|
||||||
|
|
||||||
static GList*
|
static TransSet
|
||||||
get_all_transactions (Account *account, bool descendants)
|
get_all_transactions (Account *account, bool descendants)
|
||||||
{
|
{
|
||||||
GHashTable *ht = g_hash_table_new (g_direct_hash, g_direct_equal);
|
TransSet set;
|
||||||
add_transactions (account, &ht);
|
auto add_transactions = [&set](auto a)
|
||||||
|
{ gnc_account_foreach_split (a, [&set](auto s){ set.insert (xaccSplitGetParent (s)); }, false); };
|
||||||
|
add_transactions (account);
|
||||||
if (descendants)
|
if (descendants)
|
||||||
gnc_account_foreach_descendant (account, (AccountCb)add_transactions, &ht);
|
gnc_account_foreach_descendant (account, add_transactions);
|
||||||
GList *rv = g_hash_table_get_keys (ht);
|
return set;
|
||||||
g_hash_table_destroy (ht);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
@ -144,14 +141,13 @@ AccountScrubOrphans (Account *acc, bool descendants, QofPercentageFunc percentag
|
|||||||
if (!acc) return;
|
if (!acc) return;
|
||||||
scrub_depth++;
|
scrub_depth++;
|
||||||
|
|
||||||
GList *transactions = get_all_transactions (acc, descendants);
|
auto transactions = get_all_transactions (acc, descendants);
|
||||||
gint total_trans = g_list_length (transactions);
|
auto total_trans = transactions.size();
|
||||||
const char *message = _( "Looking for orphans in transaction: %u of %u");
|
const char *message = _("Looking for orphans in transaction: %u of %zu");
|
||||||
guint current_trans = 0;
|
guint current_trans = 0;
|
||||||
|
|
||||||
for (GList *node = transactions; node; current_trans++, node = node->next)
|
for (auto trans : transactions)
|
||||||
{
|
{
|
||||||
Transaction *trans = GNC_TRANSACTION(node->data);
|
|
||||||
if (current_trans % 10 == 0)
|
if (current_trans % 10 == 0)
|
||||||
{
|
{
|
||||||
char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
|
char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
|
||||||
@ -161,11 +157,10 @@ AccountScrubOrphans (Account *acc, bool descendants, QofPercentageFunc percentag
|
|||||||
}
|
}
|
||||||
|
|
||||||
TransScrubOrphansFast (trans, gnc_account_get_root (acc));
|
TransScrubOrphansFast (trans, gnc_account_get_root (acc));
|
||||||
|
current_trans++;
|
||||||
}
|
}
|
||||||
(percentagefunc)(nullptr, -1.0);
|
(percentagefunc)(nullptr, -1.0);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
|
|
||||||
g_list_free (transactions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -359,22 +354,22 @@ static void
|
|||||||
AccountScrubImbalance (Account *acc, bool descendants,
|
AccountScrubImbalance (Account *acc, bool descendants,
|
||||||
QofPercentageFunc percentagefunc)
|
QofPercentageFunc percentagefunc)
|
||||||
{
|
{
|
||||||
const char *message = _( "Looking for imbalances in transaction date %s: %u of %u");
|
const char *message = _("Looking for imbalances in transaction date %s: %u of %zu");
|
||||||
|
|
||||||
if (!acc) return;
|
if (!acc) return;
|
||||||
|
|
||||||
QofBook *book = qof_session_get_book (gnc_get_current_session ());
|
QofBook *book = qof_session_get_book (gnc_get_current_session ());
|
||||||
Account *root = gnc_book_get_root_account (book);
|
Account *root = gnc_book_get_root_account (book);
|
||||||
GList *transactions = get_all_transactions (acc, descendants);
|
auto transactions = get_all_transactions (acc, descendants);
|
||||||
guint count = g_list_length (transactions), curr_trans = 0;
|
auto count = transactions.size();
|
||||||
|
auto curr_trans = 0;
|
||||||
|
|
||||||
scrub_depth++;
|
scrub_depth++;
|
||||||
for (GList *node = transactions; node; node = node->next, curr_trans++)
|
for (auto trans : transactions)
|
||||||
{
|
{
|
||||||
Transaction *trans = GNC_TRANSACTION(node->data);
|
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
|
|
||||||
PINFO("Start processing transaction %d of %d", curr_trans + 1, count);
|
PINFO("Start processing transaction %d of %zu", curr_trans + 1, count);
|
||||||
|
|
||||||
if (curr_trans % 10 == 0)
|
if (curr_trans % 10 == 0)
|
||||||
{
|
{
|
||||||
@ -389,12 +384,11 @@ AccountScrubImbalance (Account *acc, bool descendants,
|
|||||||
xaccTransScrubCurrency(trans);
|
xaccTransScrubCurrency(trans);
|
||||||
xaccTransScrubImbalance (trans, root, nullptr);
|
xaccTransScrubImbalance (trans, root, nullptr);
|
||||||
|
|
||||||
PINFO("Finished processing transaction %d of %d", curr_trans + 1, count);
|
PINFO("Finished processing transaction %d of %zu", curr_trans + 1, count);
|
||||||
|
curr_trans++;
|
||||||
}
|
}
|
||||||
(percentagefunc)(nullptr, -1.0);
|
(percentagefunc)(nullptr, -1.0);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
|
|
||||||
g_list_free (transactions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user