From 4bcb92fc47181c62af62a55377b62dcfa02252ae Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 24 May 2020 14:49:51 +0200 Subject: Use a more generic 'prefetch' method instead of isValid(). --- src/modinfo.cpp | 2 +- src/modinfo.h | 12 ++++++++++++ src/modinfowithconflictinfo.cpp | 5 +++++ src/modinfowithconflictinfo.h | 9 +++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/modinfo.cpp b/src/modinfo.cpp index eb0f0b4f..15fa71da 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -288,7 +288,7 @@ void ModInfo::updateFromDisc(const QString &modDirectory, std::sort(s_Collection.begin(), s_Collection.end(), ModInfo::ByName); - parallelMap(std::begin(s_Collection), std::end(s_Collection), &ModInfo::isValid, refreshThreadCount); + parallelMap(std::begin(s_Collection), std::end(s_Collection), &ModInfo::prefetch, refreshThreadCount); updateIndices(); diff --git a/src/modinfo.h b/src/modinfo.h index 37a2d24d..29e6124d 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -815,8 +815,20 @@ signals: protected: + /** + * + */ ModInfo(PluginContainer *pluginContainer); + /** + * @brief Prefetch content for this mod. + * + * This method can be used to prefetch content from the mod, e.g., for isValid() + * or getContents(). This method will only be called when first creating the mod + * using multiple threads for all the mods. + */ + virtual void prefetch() = 0; + static void updateIndices(); static bool ByName(const ModInfo::Ptr &LHS, const ModInfo::Ptr &RHS); diff --git a/src/modinfowithconflictinfo.cpp b/src/modinfowithconflictinfo.cpp index 45ecffb7..d2202c3d 100644 --- a/src/modinfowithconflictinfo.cpp +++ b/src/modinfowithconflictinfo.cpp @@ -309,6 +309,11 @@ std::shared_ptr ModInfoWithConflictInfo::contentFileTree() cons return m_FileTree; } +void ModInfoWithConflictInfo::prefetch() { + // Populating the tree to 1-depth: + contentFileTree()->size(); +} + bool ModInfoWithConflictInfo::doTestValid() const { auto mdc = m_GamePlugin->feature(); diff --git a/src/modinfowithconflictinfo.h b/src/modinfowithconflictinfo.h index 5bc1d585..68675397 100644 --- a/src/modinfowithconflictinfo.h +++ b/src/modinfowithconflictinfo.h @@ -108,6 +108,15 @@ private: protected: + /** + * @brief Prefetch content for this mod. + * + * This method can be used to prefetch content from the mod, e.g., for isValid() + * or getContents(). This method will only be called when first creating the mod + * using multiple threads for all the mods. + */ + virtual void prefetch() override; + // Current game plugin running in MO2: MOBase::IPluginGame const * const m_GamePlugin; -- cgit v1.3.1