diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-05-24 23:33:21 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-05-24 23:33:21 +0200 |
| commit | 238e233c18d22d01e966efaa86975f5f37bb7fa2 (patch) | |
| tree | 3c4eb7af80d4e47fa85f296e5c5aafbed0b5e415 /src/modinfowithconflictinfo.h | |
| parent | 0aac4f3291d65ebc1b0bbee744fca347ecef7022 (diff) | |
Use memoization for file tree, contents and validity of ModInfo.
Diffstat (limited to 'src/modinfowithconflictinfo.h')
| -rw-r--r-- | src/modinfowithconflictinfo.h | 31 |
1 files changed, 24 insertions, 7 deletions
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 <ifiletree.h> +#include "thread_utils.h" #include "modinfo.h" #include <QTime> @@ -21,6 +22,11 @@ public: virtual bool isValid() const override; /** + * @return a list of content types contained in a mod + */ + virtual std::vector<EContent> getContents() const override; + + /** * @brief clear all caches held for this mod */ virtual void clearCaches() override; @@ -49,13 +55,20 @@ 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<EContent> 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<const MOBase::IFileTree> 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<const MOBase::IFileTree> m_FileTree = nullptr; + MOShared::MemoizedLocked< + std::shared_ptr<const MOBase::IFileTree>, + decltype(&ModInfoWithConflictInfo::updateFileTree)> m_FileTree; + MOShared::MemoizedLocked<bool, decltype(&ModInfoWithConflictInfo::doTestValid)> m_Valid; + MOShared::MemoizedLocked<std::vector<EContent>, decltype(&ModInfoWithConflictInfo::doGetContents)> m_Contents; MOShared::DirectoryEntry **m_DirectoryStructure; |
