From ebd85f64028a395db394be4e78ec95dfe3c9fe5b Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Mon, 9 Oct 2023 20:30:40 +0200 Subject: [PATCH] Performance: Properly reuse cache --- src/overview.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/overview.cpp b/src/overview.cpp index 5ecdf79..539c94d 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -252,7 +252,7 @@ void add_values_column(budget::month month, using acc_data_t = cpp::string_hash_map>; template -std::pair aggregate(const Data & data, bool full, bool disable_groups, const std::string& separator, Functor&& func){ +std::pair aggregate(data_cache & cache, const Data & data, bool full, bool disable_groups, const std::string& separator, Functor&& func){ budget::money total; acc_data_t acc_data; @@ -283,7 +283,6 @@ std::pair aggregate(const Data & data, bool full, boo } } - data_cache cache; for (const auto& account : current_accounts(cache)) { if (!acc_data.contains(account.name)) { acc_data[account.name]; @@ -295,7 +294,7 @@ std::pair aggregate(const Data & data, bool full, boo template void aggregate_overview(const Data & data, budget::writer& w, bool full, bool disable_groups, const std::string& separator, Functor&& func){ - auto [total, acc_data] = aggregate(data, full, disable_groups, separator, func); + auto [total, acc_data] = aggregate(w.cache, data, full, disable_groups, separator, func); cpp::string_hash_map totals; @@ -359,7 +358,7 @@ void aggregate_overview_month(const Data & data, budget::writer& w, bool full, b months = 12 - budget::start_month(w.cache, year) + 1; } - auto [total, acc_data] = aggregate(data, full, disable_groups, separator, func); + auto [total, acc_data] = aggregate(w.cache, data, full, disable_groups, separator, func); cpp::string_hash_map totals; @@ -426,7 +425,7 @@ budget::money future_value(budget::money start) { template void aggregate_overview_fv(const Data & data, budget::writer& w, bool full, bool disable_groups, const std::string& separator, Functor&& func){ - auto [total, acc_data] = aggregate(data, full, disable_groups, separator, func); + auto [total, acc_data] = aggregate(w.cache, data, full, disable_groups, separator, func); cpp::string_hash_map totals;