From: Mikko Rasa Date: Wed, 15 Aug 2018 00:11:51 +0000 (+0300) Subject: Favor vector over list for simple types X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d0663f70ea5caea2db3c6d3c846ec67410db3498;p=poefilter.git Favor vector over list for simple types --- diff --git a/source/choicecondition.h b/source/choicecondition.h index 5a45329..df4dacf 100644 --- a/source/choicecondition.h +++ b/source/choicecondition.h @@ -20,7 +20,7 @@ public: virtual Condition *clone() const; virtual bool can_merge(const Condition &, const CompoundCondition &) const; virtual void add_lines(std::list &) const; - virtual void add_merged_lines(const std::list &, const CompoundCondition &, std::list &) const; + virtual void add_merged_lines(const std::vector &, const CompoundCondition &, std::list &) const; }; @@ -67,12 +67,12 @@ void ChoiceCondition::add_lines(std::list &st) const } template -void ChoiceCondition::add_merged_lines(const std::list &conditions, const CompoundCondition &parent, std::list &st) const +void ChoiceCondition::add_merged_lines(const std::vector &conditions, const CompoundCondition &parent, std::list &st) const { if(dynamic_cast(&parent)) { std::string line = Traits::get_keyword(); - for(std::list::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) line += Msp::format(" \"%s\"", static_cast *>(*i)->value); FilterStatement::add_line(st, line); } diff --git a/source/condition.cpp b/source/condition.cpp index 12ee730..9ff02aa 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -6,13 +6,13 @@ using namespace Msp; CompoundCondition::~CompoundCondition() { - for(list::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + for(vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) delete *i; } void CompoundCondition::clone_to(CompoundCondition &other) const { - for(list::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + for(vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) other.add((*i)->clone()); } @@ -31,7 +31,7 @@ Condition *AndCondition::clone() const void AndCondition::add_lines(list &st) const { - for(list::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + for(vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) (*i)->add_lines(st); } @@ -46,7 +46,7 @@ Condition *OrCondition::clone() const void OrCondition::add_lines(list &st) const { bool merge = conditions.size()>1; - for(list::const_iterator i=conditions.begin(); (merge && ++i!=conditions.end()); ) + for(vector::const_iterator i=conditions.begin(); (merge && ++i!=conditions.end()); ) merge = conditions.front()->can_merge(**i, *this); if(merge) @@ -54,7 +54,7 @@ void OrCondition::add_lines(list &st) const else { list result; - for(list::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) + for(vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { list sub_result = st; (*i)->add_lines(sub_result); diff --git a/source/condition.h b/source/condition.h index 59976aa..90c844e 100644 --- a/source/condition.h +++ b/source/condition.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "rarity.h" @@ -19,14 +20,14 @@ public: virtual Condition *clone() const = 0; virtual bool can_merge(const Condition &, const CompoundCondition &) const { return false; } virtual void add_lines(std::list &) const = 0; - virtual void add_merged_lines(const std::list &, const CompoundCondition &, std::list &) const { } + virtual void add_merged_lines(const std::vector &, const CompoundCondition &, std::list &) const { } }; class CompoundCondition: public Condition { protected: - std::list conditions; + std::vector conditions; public: virtual ~CompoundCondition(); diff --git a/source/filter.cpp b/source/filter.cpp index 0f7a20e..02f8c3f 100644 --- a/source/filter.cpp +++ b/source/filter.cpp @@ -94,7 +94,7 @@ bool Filter::Loader::category_order(const Category *c1, const Category *c2) void Filter::Loader::add_categories(const string &name, bool show) { - list categs; + vector categs; if(name.find('*')!=string::npos) { poe.find_categories(glob_to_re(name), categs); @@ -102,12 +102,12 @@ void Filter::Loader::add_categories(const string &name, bool show) if(categs.empty()) throw key_error(name); - categs.sort(&category_order); + sort(categs, &category_order); } else categs.push_back(&poe.get_category(name)); - for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) + for(vector::const_iterator i=categs.begin(); i!=categs.end(); ++i) { bool found = false; for(list::const_iterator j=obj.blocks.begin(); (!found && j!=obj.blocks.end()); ++j) @@ -128,7 +128,7 @@ void Filter::Loader::add_categories(const string &name, bool show) void Filter::Loader::cancel(const string &name) { - list categs; + vector categs; if(name.find('*')!=string::npos) { poe.find_categories(glob_to_re(name), categs); @@ -139,7 +139,7 @@ void Filter::Loader::cancel(const string &name) else categs.push_back(&poe.get_category(name)); - for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) + for(vector::const_iterator i=categs.begin(); i!=categs.end(); ++i) for(list::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j) if(j->category==*i) { diff --git a/source/poefilter.cpp b/source/poefilter.cpp index b90afc5..4599583 100644 --- a/source/poefilter.cpp +++ b/source/poefilter.cpp @@ -34,7 +34,7 @@ const Category &PoeFilter::get_category(const string &name) const return get_item(categories, name); } -void PoeFilter::find_categories(const Regex &re, list &categs) const +void PoeFilter::find_categories(const Regex &re, vector &categs) const { for(map::const_iterator i=categories.begin(); i!=categories.end(); ++i) if(re.match(i->first)) diff --git a/source/poefilter.h b/source/poefilter.h index 666d0a6..dec5fd3 100644 --- a/source/poefilter.h +++ b/source/poefilter.h @@ -37,7 +37,7 @@ public: const Theme &get_theme() const { return theme; } const Category &get_category(const std::string &) const; - void find_categories(const Msp::Regex &, std::list &) const; + void find_categories(const Msp::Regex &, std::vector &) const; const Filter &get_filter(const std::string &) const; };