From 238e233c18d22d01e966efaa86975f5f37bb7fa2 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 24 May 2020 23:33:21 +0200 Subject: Use memoization for file tree, contents and validity of ModInfo. --- src/modinfowithconflictinfo.h | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/modinfowithconflictinfo.h') diff --git a/src/modinfowithconflictinfo.h b/src/modinfowithconflictinfo.h index 68675397..3adbb998 100644 --- a/src/modinfowithconflictinfo.h +++ b/src/modinfowithconflictinfo.h @@ -3,6 +3,7 @@ #include +#include "thread_utils.h" #include "modinfo.h" #include @@ -20,6 +21,11 @@ public: **/ virtual bool isValid() const override; + /** + * @return a list of content types contained in a mod + */ + virtual std::vector getContents() const override; + /** * @brief clear all caches held for this mod */ @@ -49,12 +55,19 @@ public slots: protected: /** - * @brief check if the content of this mod is valid. + * @brief Check if the content of this mod is valid. * - * @return true if the content is valid, false otherwize. + * @return true if the content is valid, false otherwise. **/ virtual bool doTestValid() const; + /** + * @brief Compute the contents for this mod. + * + * @return the contents for this mod. + **/ + virtual std::vector doGetContents() const { return {}; } + /** * @brief Retrieve a file tree corresponding to the underlying disk content * of this mod. @@ -122,12 +135,16 @@ protected: private: - // Mutex: - mutable std::mutex m_Mutex; + /** + * @return a file tree for this mod. + */ + std::shared_ptr updateFileTree() const; - // File tree representing the content of the disk. A null pointer indicates - // that the content needs to be loaded from the disk: - mutable std::shared_ptr m_FileTree = nullptr; + MOShared::MemoizedLocked< + std::shared_ptr, + decltype(&ModInfoWithConflictInfo::updateFileTree)> m_FileTree; + MOShared::MemoizedLocked m_Valid; + MOShared::MemoizedLocked, decltype(&ModInfoWithConflictInfo::doGetContents)> m_Contents; MOShared::DirectoryEntry **m_DirectoryStructure; -- cgit v1.3.1