diff options
author | Julian Eisel <julian@blender.org> | 2022-08-18 21:15:36 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-08-18 21:22:55 +0300 |
commit | d2255aa4ed6d6b3fc3a42871a649682e357a305e (patch) | |
tree | b9f26ef1bf0548fb29b91431e9423f55db37a7fd /source/blender/blenkernel/BKE_outliner_treehash.hh | |
parent | 75cca8360f611f6b79b65228d18fd6597267417f (diff) |
Outliner: Refactor outliner tree-hash interfaces with C++
- Turn storage into an object with "automatic" memory management (RAII)
so freeing is implicit and reliable.
- Turn functions into member functions, to have the data and its
functions close together with controlled access that increases
encapsulation and hiding implementation details.
- Use references to indicate null is not an expected value.
- Related minor cleanup (comments, use const etc.)
Couldn't spot any changes in performance.
Diffstat (limited to 'source/blender/blenkernel/BKE_outliner_treehash.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_outliner_treehash.hh | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/source/blender/blenkernel/BKE_outliner_treehash.hh b/source/blender/blenkernel/BKE_outliner_treehash.hh index fc0ab35cf38..f72cec21dbc 100644 --- a/source/blender/blenkernel/BKE_outliner_treehash.hh +++ b/source/blender/blenkernel/BKE_outliner_treehash.hh @@ -3,45 +3,52 @@ /** \file * \ingroup bke + * + * Hash table of tree-store elements (#TreeStoreElem) for fast lookups via a (id, type, index) + * tuple as key. + * + * The Outliner may have to perform many lookups for rebuilding complex trees, so this should be + * treated as performance sensitive. */ -#ifdef __cplusplus -extern "C" { -#endif +#include <memory> struct BLI_mempool; struct ID; struct GHash; struct TreeStoreElem; -/* create and fill hashtable with treestore elements */ -GHash *BKE_outliner_treehash_create_from_treestore(BLI_mempool *treestore); +namespace blender::bke::outliner::treehash { -/* full rebuild for already allocated hashtable */ -GHash *BKE_outliner_treehash_rebuild_from_treestore(GHash *treehash, BLI_mempool *treestore); +class TreeHash { + GHash *treehash_ = nullptr; -/* clear element usage flags */ -void BKE_outliner_treehash_clear_used(GHash *treehash); + public: + ~TreeHash(); -/* Add/remove hashtable elements */ -void BKE_outliner_treehash_add_element(GHash *treehash, TreeStoreElem *elem); -void BKE_outliner_treehash_remove_element(GHash *treehash, TreeStoreElem *elem); + /* create and fill hashtable with treestore elements */ + static std::unique_ptr<TreeHash> create_from_treestore(BLI_mempool &treestore); -/* find first unused element with specific type, nr and id */ -struct TreeStoreElem *BKE_outliner_treehash_lookup_unused(GHash *treehash, - short type, - short nr, - ID *id); + /* full rebuild for already allocated hashtable */ + void rebuild_from_treestore(BLI_mempool &treestore); -/* find user or unused element with specific type, nr and id */ -struct TreeStoreElem *BKE_outliner_treehash_lookup_any(GHash *treehash, - short type, - short nr, - ID *id); + /* clear element usage flags */ + void clear_used(); -/* free treehash structure */ -void BKE_outliner_treehash_free(GHash *treehash); + /* Add/remove hashtable elements */ + void add_element(TreeStoreElem &elem); + void remove_element(TreeStoreElem &elem); -#ifdef __cplusplus -} -#endif + /* find first unused element with specific type, nr and id */ + TreeStoreElem *lookup_unused(short type, short nr, ID *id) const; + + /* find user or unused element with specific type, nr and id */ + TreeStoreElem *lookup_any(short type, short nr, ID *id) const; + + private: + TreeHash() = default; + + void fill_treehash(BLI_mempool &treestore); +}; + +} // namespace blender::bke::outliner::treehash |