From fcaaa372019b525980e40b148a1d542ab3acced9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 6 Sep 2004 05:38:32 -0400 Subject: switch from using deque back to list; affects speed by up to 30%! --- acprep | 3 +-- config.cc | 8 ++++---- ledger.h | 8 ++++---- main.cc | 2 +- option.cc | 16 ++++++++-------- option.h | 4 ++-- walk.cc | 4 ++-- walk.h | 31 +++++++++++++++++++++++-------- 8 files changed, 45 insertions(+), 31 deletions(-) diff --git a/acprep b/acprep index a1a5ea16..aa3d01c0 100755 --- a/acprep +++ b/acprep @@ -22,8 +22,7 @@ if [ "$1" = "--debug" ]; then CXXFLAGS="-g" --enable-debug --disable-shared elif [ "$1" = "--opt" ]; then ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \ - CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450 -fPIC" \ - --enable-standalone --disable-shared + CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450" --disable-shared elif [ "$1" = "--perf" ]; then ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g -pg" fi diff --git a/config.cc b/config.cc index f090a09e..0dff2a47 100644 --- a/config.cc +++ b/config.cc @@ -47,8 +47,8 @@ config_t::config_t() static void regexps_to_predicate(config_t& config, - std::deque::const_iterator begin, - std::deque::const_iterator end, + std::list::const_iterator begin, + std::list::const_iterator end, const bool account_regexp = false, const bool add_account_short_masks = false) { @@ -57,7 +57,7 @@ regexps_to_predicate(config_t& config, // Treat the remaining command-line arguments as regular // expressions, used for refining report results. - for (std::deque::const_iterator i = begin; + for (std::list::const_iterator i = begin; i != end; i++) if ((*i)[0] == '-') { @@ -137,7 +137,7 @@ void config_t::process_options(const std::string& command, // Treat the remaining command-line arguments as regular // expressions, used for refining report results. - std::deque::iterator i = arg; + std::list::iterator i = arg; for (; i != args_end; i++) if (*i == "--") break; diff --git a/ledger.h b/ledger.h index e52a1e83..1d64e4e1 100644 --- a/ledger.h +++ b/ledger.h @@ -11,7 +11,7 @@ // #include -#include +#include #include #include #include @@ -121,7 +121,7 @@ value_t& add_transaction_to(const transaction_t& xact, value_t& value) return value; } -typedef std::deque transactions_list; +typedef std::list transactions_list; class entry_t { @@ -214,8 +214,8 @@ inline std::ostream& operator<<(std::ostream& out, const account_t& acct) { } -typedef std::deque entries_list; -typedef std::deque strings_list; +typedef std::list entries_list; +typedef std::list strings_list; class journal_t { diff --git a/main.cc b/main.cc index 6ae0bb21..42501544 100644 --- a/main.cc +++ b/main.cc @@ -230,7 +230,7 @@ int parse_and_report(int argc, char * argv[], char * envp[]) TIMER_START(process_opts); - std::deque args; + std::list args; process_arguments(argc - 1, argv + 1, false, args); if (args.empty()) { diff --git a/option.cc b/option.cc index 7e0a74f3..f4053e4e 100644 --- a/option.cc +++ b/option.cc @@ -6,7 +6,7 @@ #include "util.h" -static std::deque options; +static std::list options; void register_option(const std::string& label, const std::string& opt_chars, @@ -50,7 +50,7 @@ static inline void process_option(const option_t& opt, bool process_option(const std::string& opt, const char * arg) { - for (std::deque::iterator i = options.begin(); + for (std::list::iterator i = options.begin(); i != options.end(); i++) if ((*i).long_opt == opt) { @@ -66,7 +66,7 @@ bool process_option(const std::string& opt, const char * arg) } void process_arguments(int argc, char ** argv, const bool anywhere, - std::deque& args) + std::list& args) { int index = 0; for (char ** i = argv; index < argc; i++, index++) { @@ -87,7 +87,7 @@ void process_arguments(int argc, char ** argv, const bool anywhere, if ((*i)[2] == '\0') break; - for (std::deque::iterator j = options.begin(); + for (std::list::iterator j = options.begin(); j != options.end(); j++) if ((*j).wants_arg) { @@ -111,7 +111,7 @@ void process_arguments(int argc, char ** argv, const bool anywhere, std::cerr << "Error: illegal option " << *i << std::endl; std::exit(1); } else { - for (std::deque::iterator j = options.begin(); + for (std::list::iterator j = options.begin(); j != options.end(); j++) if ((*i)[1] == (*j).short_opt) { @@ -180,7 +180,7 @@ struct func_option_wrapper : public option_handler } }; -static std::deque wrappers; +static std::list wrappers; void py_register_option(const std::string& long_opt, const std::string& short_opt, object func) @@ -200,11 +200,11 @@ list py_process_arguments(list args, bool anywhere = false) for (int i = 0; i < l; i++) strs.push_back(extract(args[i])); - std::deque newargs; + std::list newargs; process_arguments(strs.size(), &strs.front(), anywhere, newargs); list py_newargs; - for (std::deque::iterator i = newargs.begin(); + for (std::list::iterator i = newargs.begin(); i != newargs.end(); i++) py_newargs.append(*i); diff --git a/option.h b/option.h index 44ca5b3b..fe073274 100644 --- a/option.h +++ b/option.h @@ -1,7 +1,7 @@ #ifndef _OPTION_H #define _OPTION_H -#include +#include #include struct option_handler { @@ -23,7 +23,7 @@ void register_option(const std::string& label, const std::string& opt_chars, option_handler& option); bool process_option(const std::string& opt, const char * arg = NULL); void process_arguments(int argc, char ** argv, const bool anywhere, - std::deque& args); + std::list& args); void process_environment(char ** envp, const std::string& tag); #endif // _OPTION_H diff --git a/walk.cc b/walk.cc index a8111597..61c3fa30 100644 --- a/walk.cc +++ b/walk.cc @@ -8,7 +8,7 @@ void sort_transactions::flush() std::stable_sort(transactions.begin(), transactions.end(), compare_items(sort_order)); - for (std::deque::iterator i = transactions.begin(); + for (transactions_deque::iterator i = transactions.begin(); i != transactions.end(); i++) (*handler)(**i); @@ -290,7 +290,7 @@ void interval_transactions::operator()(transaction_t& xact) void dow_transactions::flush() { for (int i = 0; i < 7; i++) { - for (std::deque::iterator d = days_of_the_week[i].begin(); + for (transactions_list::iterator d = days_of_the_week[i].begin(); d != days_of_the_week[i].end(); d++) subtotal_transactions::operator()(**d); diff --git a/walk.h b/walk.h index 00296082..d9946ed9 100644 --- a/walk.h +++ b/walk.h @@ -67,6 +67,9 @@ class compare_items { // Transaction handlers // +typedef std::deque transactions_deque; +typedef std::deque entries_deque; + inline void walk_transactions(transactions_list::iterator begin, transactions_list::iterator end, item_handler& handler) { @@ -74,7 +77,19 @@ inline void walk_transactions(transactions_list::iterator begin, handler(**i); } -inline void walk_transactions(transactions_list& deque, +inline void walk_transactions(transactions_list& list, + item_handler& handler) { + walk_transactions(list.begin(), list.end(), handler); +} + +inline void walk_transactions(transactions_deque::iterator begin, + transactions_deque::iterator end, + item_handler& handler) { + for (transactions_deque::iterator i = begin; i != end; i++) + handler(**i); +} + +inline void walk_transactions(transactions_deque& deque, item_handler& handler) { walk_transactions(deque.begin(), deque.end(), handler); } @@ -179,8 +194,8 @@ class set_account_value : public item_handler class sort_transactions : public item_handler { - std::deque transactions; - const value_expr_t * sort_order; + transactions_deque transactions; + const value_expr_t * sort_order; public: sort_transactions(item_handler * handler, @@ -387,7 +402,7 @@ class interval_transactions : public subtotal_transactions class dow_transactions : public subtotal_transactions { - std::deque days_of_the_week[7]; + transactions_list days_of_the_week[7]; public: dow_transactions(item_handler * handler) @@ -459,11 +474,11 @@ inline void sum_accounts(account_t& account) { ACCT_DATA_(account)->count += ACCT_DATA_(account)->subcount; } -typedef std::deque accounts_list; +typedef std::deque accounts_deque; inline void sort_accounts(account_t& account, const value_expr_t * sort_order, - accounts_list& accounts) { + accounts_deque& accounts) { for (accounts_map::iterator i = account.accounts.begin(); i != account.accounts.end(); i++) @@ -479,9 +494,9 @@ inline void walk_accounts(account_t& account, handler(account); if (sort_order) { - accounts_list accounts; + accounts_deque accounts; sort_accounts(account, sort_order, accounts); - for (accounts_list::const_iterator i = accounts.begin(); + for (accounts_deque::const_iterator i = accounts.begin(); i != accounts.end(); i++) walk_accounts(**i, handler, sort_order); -- cgit v1.2.3