From f17aacae08eaf88403cd4a8378fa095c900bae7b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 May 2024 12:52:53 +0300 Subject: [PATCH] Change most remaining uses of std::list to std::vector --- source/builtinsource.cpp | 4 ++-- source/builtinsource.h | 2 +- source/collection.cpp | 4 ++-- source/collection.h | 22 +++++++++++----------- source/collectionsource.h | 7 ++----- source/directorysource.cpp | 4 ++-- source/directorysource.h | 2 +- source/packsource.cpp | 9 +++++---- source/packsource.h | 4 ++-- tool/tool.cpp | 4 ++-- 10 files changed, 30 insertions(+), 32 deletions(-) diff --git a/source/builtinsource.cpp b/source/builtinsource.cpp index 836d15d..64fb28d 100644 --- a/source/builtinsource.cpp +++ b/source/builtinsource.cpp @@ -23,9 +23,9 @@ bool BuiltinSource::is_loadable(const CollectionItemTypeBase &, const string &na return objects.count(name); } -CollectionSource::NameList BuiltinSource::get_names(const CollectionItemTypeBase &type) const +vector BuiltinSource::get_names(const CollectionItemTypeBase &type) const { - NameList names; + vector names; for(const auto &kvp: objects) if(type.match_name(kvp.first)) names.push_back(kvp.first); diff --git a/source/builtinsource.h b/source/builtinsource.h index 1a78b14..cbb044e 100644 --- a/source/builtinsource.h +++ b/source/builtinsource.h @@ -26,7 +26,7 @@ public: void add_object(const std::string &, const char *); bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; - NameList get_names(const CollectionItemTypeBase &) const override; + std::vector get_names(const CollectionItemTypeBase &) const override; void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; std::unique_ptr open(const std::string &) const override; }; diff --git a/source/collection.cpp b/source/collection.cpp index 6e857b5..7243c5d 100644 --- a/source/collection.cpp +++ b/source/collection.cpp @@ -60,7 +60,7 @@ const Variant *Collection::find_var(const string &name, const CollectionItemType return (i!=items.end() ? &i->second : nullptr); } -void Collection::gather_items(vector *vars, list *names, const CollectionItemTypeBase &type, bool include_sources) const +void Collection::gather_items(vector *vars, vector *names, const CollectionItemTypeBase &type, bool include_sources) const { for(const auto &kvp: items) if(type.check_item_type(kvp.second)) @@ -122,7 +122,7 @@ unique_ptr Collection::open_raw(const string &name) const return nullptr; } -void Collection::gather_names_from_sources(list &names, const CollectionItemTypeBase &type) const +void Collection::gather_names_from_sources(vector &names, const CollectionItemTypeBase &type) const { set new_names; for(const CollectionSource *s: sources) diff --git a/source/collection.h b/source/collection.h index bc2a591..ae6ec30 100644 --- a/source/collection.h +++ b/source/collection.h @@ -144,18 +144,18 @@ private: T &extract(const Variant &var) const; template - std::list extract_list(const std::vector &vars) const + std::vector extract_list(const std::vector &vars) const { - std::list result; + std::vector result; for(const Variant *v: vars) result.push_back(&extract(*v)); return result; } - void gather_items(std::vector *, std::list *, const CollectionItemTypeBase &, bool) const; + void gather_items(std::vector *, std::vector *, const CollectionItemTypeBase &, bool) const; template - void gather_items(std::vector *vars, std::list *names, const CollectionItemTypeBase *type, bool include_sources) const + void gather_items(std::vector *vars, std::vector *names, const CollectionItemTypeBase *type, bool include_sources) const { if(type || (type = get_type())) gather_items(vars, names, *type, include_sources); @@ -166,9 +166,9 @@ private: public: /// Returns a list of the names of objects of one type in the collection. template - std::list get_names() const + std::vector get_names() const { - std::list names; + std::vector names; gather_items::type>(0, &names, 0, false); return names; } @@ -176,16 +176,16 @@ public: /** Returns a list of the names of objects of one type in the collection or available from sources. */ template - std::list get_names() + std::vector get_names() { - std::list names; + std::vector names; gather_items::type>(0, &names, 0, true); return names; } /// Returns a list of objects of one type in the collection. template - std::list get_list() const + std::vector get_all() const { std::vector vars; gather_items::type>(&vars, 0, 0, false); @@ -195,7 +195,7 @@ public: /** Returns a list of objects of one type, loading them from sources if necessary. */ template - std::list get_list() + std::vector get_all() { CollectionItemTypeBase *type = get_type::type>(); if(type) @@ -282,7 +282,7 @@ public: std::unique_ptr open_raw(const std::string &) const; private: - void gather_names_from_sources(std::list &, const CollectionItemTypeBase &) const; + void gather_names_from_sources(std::vector &, const CollectionItemTypeBase &) const; void load_items_from_sources(const CollectionItemTypeBase &); diff --git a/source/collectionsource.h b/source/collectionsource.h index 10f71ba..8af70b4 100644 --- a/source/collectionsource.h +++ b/source/collectionsource.h @@ -1,9 +1,9 @@ #ifndef COLLECTIONSOURCE_H_ #define COLLECTIONSOURCE_H_ -#include #include #include +#include #include #include "mspdatafile_api.h" @@ -19,9 +19,6 @@ see DirectorySource and PackSource for concrete classes. */ class MSPDATAFILE_API CollectionSource { -public: - using NameList = std::list; - protected: CollectionSource() = default; public: @@ -32,7 +29,7 @@ public: /** Returns the names of available objects of a specific type. Implementors should use type.match_name to check which names are acceptable. */ - virtual NameList get_names(const CollectionItemTypeBase &type) const = 0; + virtual std::vector get_names(const CollectionItemTypeBase &type) const = 0; /// Loads an item into a collection. virtual void load(Collection &, const CollectionItemTypeBase &, const std::string &) const = 0; diff --git a/source/directorysource.cpp b/source/directorysource.cpp index d57397a..6defe25 100644 --- a/source/directorysource.cpp +++ b/source/directorysource.cpp @@ -20,9 +20,9 @@ bool DirectorySource::is_loadable(const CollectionItemTypeBase &, const string & return objects.count(name); } -CollectionSource::NameList DirectorySource::get_names(const CollectionItemTypeBase &type) const +vector DirectorySource::get_names(const CollectionItemTypeBase &type) const { - NameList names; + vector names; for(const auto &kvp: objects) if(type.match_name(kvp.first)) names.push_back(kvp.first); diff --git a/source/directorysource.h b/source/directorysource.h index 7e2066b..11bdd3b 100644 --- a/source/directorysource.h +++ b/source/directorysource.h @@ -22,7 +22,7 @@ public: void add_directory(const FS::Path &, bool = true); bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; - NameList get_names(const CollectionItemTypeBase &) const override; + std::vector get_names(const CollectionItemTypeBase &) const override; void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; std::unique_ptr open(const std::string &) const override; diff --git a/source/packsource.cpp b/source/packsource.cpp index dcbc7d7..6087092 100644 --- a/source/packsource.cpp +++ b/source/packsource.cpp @@ -65,9 +65,10 @@ void PackSource::add_pack(IO::Seekable *io, const string &fn, const string &filt } } -list PackSource::list_files() const +vector PackSource::list_files() const { - list result; + vector result; + result.reserve(files.size()); for(const auto &kvp: files) result.push_back(kvp.second->get_info()); return result; @@ -86,9 +87,9 @@ bool PackSource::is_loadable(const CollectionItemTypeBase &type, const string &n return true; } -CollectionSource::NameList PackSource::get_names(const CollectionItemTypeBase &type) const +vector PackSource::get_names(const CollectionItemTypeBase &type) const { - NameList names; + vector names; for(const auto &kvp: objects) { if(!kvp.second->get_keyword().empty()) diff --git a/source/packsource.h b/source/packsource.h index d7bec4a..7fa1125 100644 --- a/source/packsource.h +++ b/source/packsource.h @@ -141,10 +141,10 @@ private: public: /// Returns information about the files in the pack. - std::list list_files() const; + std::vector list_files() const; bool is_loadable(const CollectionItemTypeBase &, const std::string &) const override; - NameList get_names(const CollectionItemTypeBase &) const override; + std::vector get_names(const CollectionItemTypeBase &) const override; void load(Collection &, const CollectionItemTypeBase &, const std::string &) const override; std::unique_ptr open(const std::string &) const override; }; diff --git a/tool/tool.cpp b/tool/tool.cpp index a6b0944..a88829f 100644 --- a/tool/tool.cpp +++ b/tool/tool.cpp @@ -119,8 +119,8 @@ void DataTool::do_unpack() for(list::const_iterator i=in_fns.begin(); i!=in_fns.end(); ++i) source.add_pack_file(*i); - list files = source.list_files(); - for(list::const_iterator i=files.begin(); i!=files.end(); ++i) + vector files = source.list_files(); + for(vector::const_iterator i=files.begin(); i!=files.end(); ++i) { unique_ptr in = source.open(i->name); unique_ptr out = open_output(i->name); -- 2.45.2