From: Mikko Rasa Date: Sun, 19 Apr 2020 13:22:51 +0000 (+0300) Subject: Prefer vector over list X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a887b3f7518605c22e4b70eeb9fe136acb2ea632;p=libs%2Fdatafile.git Prefer vector over list --- diff --git a/source/collection.cpp b/source/collection.cpp index 9f135f0..129c0a8 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -44,7 +44,7 @@ const Variant &Collection::get_var(const string &name, const CollectionItemTypeB return get_item(items, name); } -void Collection::gather_items(list *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const +void Collection::gather_items(vector *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const { for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i) if(type.check_item_type(i->second)) diff --git a/source/collection.h b/source/collection.h index 005abd0..5521975 100644 --- a/source/collection.h +++ b/source/collection.h @@ -69,8 +69,8 @@ public: private: typedef std::map ItemMap; - typedef std::list TypeList; - typedef std::list SourceList; + typedef std::vector TypeList; + typedef std::vector SourceList; TypeList types; ItemMap items; @@ -128,18 +128,18 @@ private: T &extract(const Variant &var) const; template - std::list extract_list(const std::list &vars) const + std::list extract_list(const std::vector &vars) const { std::list result; - for(std::list::const_iterator i=vars.begin(); i!=vars.end(); ++i) + for(std::vector::const_iterator i=vars.begin(); i!=vars.end(); ++i) result.push_back(&extract(**i)); return result; } - void gather_items(std::list *, std::list *, const CollectionItemTypeBase &, bool) const; + void gather_items(std::vector *, std::list *, const CollectionItemTypeBase &, bool) const; template - void gather_items(std::list *vars, std::list *names, const CollectionItemTypeBase *type, bool include_sources) const + void gather_items(std::vector *vars, std::list *names, const CollectionItemTypeBase *type, bool include_sources) const { if(type || (type = get_type())) gather_items(vars, names, *type, include_sources); @@ -171,7 +171,7 @@ public: template std::list get_list() const { - std::list vars; + std::vector vars; gather_items::Type>(&vars, 0, 0, false); return extract_list(vars); } @@ -185,7 +185,7 @@ public: if(type) load_items_from_sources(*type); - std::list vars; + std::vector vars; gather_items::Type>(&vars, 0, type, true); return extract_list(vars); } diff --git a/source/loader.cpp b/source/loader.cpp index a05e5f0..55492b6 100644 --- a/source/loader.cpp +++ b/source/loader.cpp @@ -116,7 +116,7 @@ void Loader::load_statement(const Statement &st) if(!aux_loaders.empty() && !has_action(key)) { - for(list::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i) + for(vector::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i) if((*i)->has_action(key)) return (*i)->load_statement(st); } diff --git a/source/loader.h b/source/loader.h index 3e39872..de0b32d 100644 --- a/source/loader.h +++ b/source/loader.h @@ -44,7 +44,7 @@ private: const Statement *cur_st; bool sub_loaded; bool direct; - std::list aux_loaders; + std::vector aux_loaders; protected: bool check_sub_loads;