]> git.tdb.fi Git - libs/datafile.git/commitdiff
Prefer vector over list
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Apr 2020 13:22:51 +0000 (16:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Apr 2020 14:31:49 +0000 (17:31 +0300)
source/collection.cpp
source/collection.h
source/loader.cpp
source/loader.h

index 9f135f0c0ed8eab31c6ffe730b23fd683b69e98e..129c0a84f76808c14f0a8164b853e0c56d6ccb97 100644 (file)
@@ -44,7 +44,7 @@ const Variant &Collection::get_var(const string &name, const CollectionItemTypeB
        return get_item(items, name);
 }
 
-void Collection::gather_items(list<const Variant *> *vars, list<string> *names, const CollectionItemTypeBase &type, bool include_sources) const
+void Collection::gather_items(vector<const Variant *> *vars, list<string> *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))
index 005abd0db39e3c54c8b934ea784e5431164d70e4..5521975402d0526773a44bf6210c9577b87d0f79 100644 (file)
@@ -69,8 +69,8 @@ public:
 
 private:
        typedef std::map<std::string, Variant> ItemMap;
-       typedef std::list<CollectionItemTypeBase *> TypeList;
-       typedef std::list<const CollectionSource *> SourceList;
+       typedef std::vector<CollectionItemTypeBase *> TypeList;
+       typedef std::vector<const CollectionSource *> SourceList;
 
        TypeList types;
        ItemMap items;
@@ -128,18 +128,18 @@ private:
        T &extract(const Variant &var) const;
 
        template<typename T>
-       std::list<T *> extract_list(const std::list<const Variant *> &vars) const
+       std::list<T *> extract_list(const std::vector<const Variant *> &vars) const
        {
                std::list<T *> result;
-               for(std::list<const Variant *>::const_iterator i=vars.begin(); i!=vars.end(); ++i)
+               for(std::vector<const Variant *>::const_iterator i=vars.begin(); i!=vars.end(); ++i)
                        result.push_back(&extract<T>(**i));
                return result;
        }
 
-       void gather_items(std::list<const Variant *> *, std::list<std::string> *, const CollectionItemTypeBase &, bool) const;
+       void gather_items(std::vector<const Variant *> *, std::list<std::string> *, const CollectionItemTypeBase &, bool) const;
 
        template<typename T>
-       void gather_items(std::list<const Variant *> *vars, std::list<std::string> *names, const CollectionItemTypeBase *type, bool include_sources) const
+       void gather_items(std::vector<const Variant *> *vars, std::list<std::string> *names, const CollectionItemTypeBase *type, bool include_sources) const
        {
                if(type || (type = get_type<T>()))
                        gather_items(vars, names, *type, include_sources);
@@ -171,7 +171,7 @@ public:
        template<typename T>
        std::list<T *> get_list() const
        {
-               std::list<const Variant *> vars;
+               std::vector<const Variant *> vars;
                gather_items<typename RemoveConst<T>::Type>(&vars, 0, 0, false);
                return extract_list<T>(vars);
        }
@@ -185,7 +185,7 @@ public:
                if(type)
                        load_items_from_sources(*type);
 
-               std::list<const Variant *> vars;
+               std::vector<const Variant *> vars;
                gather_items<typename RemoveConst<T>::Type>(&vars, 0, type, true);
                return extract_list<T>(vars);
        }
index a05e5f0dfe187b0060cd307f21146d7f199dbb55..55492b66ce9dd04d3bed6ab211e990faafc9b6a3 100644 (file)
@@ -116,7 +116,7 @@ void Loader::load_statement(const Statement &st)
 
                if(!aux_loaders.empty() && !has_action(key))
                {
-                       for(list<Loader *>::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i)
+                       for(vector<Loader *>::const_iterator i=aux_loaders.begin(); i!=aux_loaders.end(); ++i)
                                if((*i)->has_action(key))
                                        return (*i)->load_statement(st);
                }
index 3e39872a5c2f1263d6748a761d28a52baa97e0f7..de0b32deaaa06f4aae771ff64644a68cfdfe4d11 100644 (file)
@@ -44,7 +44,7 @@ private:
        const Statement *cur_st;
        bool sub_loaded;
        bool direct;
-       std::list<Loader *> aux_loaders;
+       std::vector<Loader *> aux_loaders;
 protected:
        bool check_sub_loads;