Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-08-18 21:15:36 +0300
committerJulian Eisel <julian@blender.org>2022-08-18 21:22:55 +0300
commitd2255aa4ed6d6b3fc3a42871a649682e357a305e (patch)
treeb9f26ef1bf0548fb29b91431e9423f55db37a7fd /source/blender/editors/space_outliner
parent75cca8360f611f6b79b65228d18fd6597267417f (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/editors/space_outliner')
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.hh12
-rw-r--r--source/blender/editors/space_outliner/outliner_tree.cc30
-rw-r--r--source/blender/editors/space_outliner/outliner_utils.cc3
-rw-r--r--source/blender/editors/space_outliner/space_outliner.cc11
4 files changed, 23 insertions, 33 deletions
diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh
index 5362782dd84..80254a5cb88 100644
--- a/source/blender/editors/space_outliner/outliner_intern.hh
+++ b/source/blender/editors/space_outliner/outliner_intern.hh
@@ -42,21 +42,25 @@ class AbstractTreeDisplay;
class AbstractTreeElement;
} // namespace blender::ed::outliner
+namespace blender::bke::outliner::treehash {
+class TreeHash;
+}
+
namespace outliner = blender::ed::outliner;
+namespace treehash = blender::bke::outliner::treehash;
struct SpaceOutliner_Runtime {
/** Object to create and manage the tree for a specific display type (View Layers, Scenes,
* Blender File, etc.). */
std::unique_ptr<outliner::AbstractTreeDisplay> tree_display;
- /** Pointers to tree-store elements, grouped by `(id, type, nr)`
- * in hash-table for faster searching. */
- struct GHash *treehash;
+ /* Hash table for tree-store elements, using `(id, type, index)` as key. */
+ std::unique_ptr<treehash::TreeHash> tree_hash;
SpaceOutliner_Runtime() = default;
/** Used for copying runtime data to a duplicated space. */
SpaceOutliner_Runtime(const SpaceOutliner_Runtime &);
- ~SpaceOutliner_Runtime();
+ ~SpaceOutliner_Runtime() = default;
};
typedef enum TreeElementInsertType {
diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc
index b3b2bb59e20..05df3f9cb8f 100644
--- a/source/blender/editors/space_outliner/outliner_tree.cc
+++ b/source/blender/editors/space_outliner/outliner_tree.cc
@@ -111,10 +111,7 @@ static void outliner_storage_cleanup(SpaceOutliner *space_outliner)
if (BLI_mempool_len(ts) == unused) {
BLI_mempool_destroy(ts);
space_outliner->treestore = nullptr;
- if (space_outliner->runtime->treehash) {
- BKE_outliner_treehash_free(space_outliner->runtime->treehash);
- space_outliner->runtime->treehash = nullptr;
- }
+ space_outliner->runtime->tree_hash = nullptr;
}
else {
TreeStoreElem *tsenew;
@@ -129,16 +126,15 @@ static void outliner_storage_cleanup(SpaceOutliner *space_outliner)
}
BLI_mempool_destroy(ts);
space_outliner->treestore = new_ts;
- if (space_outliner->runtime->treehash) {
+ if (space_outliner->runtime->tree_hash) {
/* update hash table to fix broken pointers */
- BKE_outliner_treehash_rebuild_from_treestore(space_outliner->runtime->treehash,
- space_outliner->treestore);
+ space_outliner->runtime->tree_hash->rebuild_from_treestore(*space_outliner->treestore);
}
}
}
}
- else if (space_outliner->runtime->treehash) {
- BKE_outliner_treehash_clear_used(space_outliner->runtime->treehash);
+ else if (space_outliner->runtime->tree_hash) {
+ space_outliner->runtime->tree_hash->clear_used();
}
}
}
@@ -151,15 +147,14 @@ static void check_persistent(
space_outliner->treestore = BLI_mempool_create(
sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
}
- if (space_outliner->runtime->treehash == nullptr) {
- space_outliner->runtime->treehash = static_cast<GHash *>(
- BKE_outliner_treehash_create_from_treestore(space_outliner->treestore));
+ if (space_outliner->runtime->tree_hash == nullptr) {
+ space_outliner->runtime->tree_hash = treehash::TreeHash::create_from_treestore(
+ *space_outliner->treestore);
}
/* find any unused tree element in treestore and mark it as used
* (note that there may be multiple unused elements in case of linked objects) */
- TreeStoreElem *tselem = BKE_outliner_treehash_lookup_unused(
- space_outliner->runtime->treehash, type, nr, id);
+ TreeStoreElem *tselem = space_outliner->runtime->tree_hash->lookup_unused(type, nr, id);
if (tselem) {
te->store_elem = tselem;
tselem->used = 1;
@@ -174,7 +169,7 @@ static void check_persistent(
tselem->used = 0;
tselem->flag = TSE_CLOSED;
te->store_elem = tselem;
- BKE_outliner_treehash_add_element(space_outliner->runtime->treehash, tselem);
+ space_outliner->runtime->tree_hash->add_element(*tselem);
}
/** \} */
@@ -1685,10 +1680,9 @@ void outliner_build_tree(Main *mainvar,
space_outliner->search_flags &= ~SO_SEARCH_RECURSIVE;
}
- if (space_outliner->runtime->treehash && (space_outliner->storeflag & SO_TREESTORE_REBUILD) &&
+ if (space_outliner->runtime->tree_hash && (space_outliner->storeflag & SO_TREESTORE_REBUILD) &&
space_outliner->treestore) {
- BKE_outliner_treehash_rebuild_from_treestore(space_outliner->runtime->treehash,
- space_outliner->treestore);
+ space_outliner->runtime->tree_hash->rebuild_from_treestore(*space_outliner->treestore);
}
space_outliner->storeflag &= ~SO_TREESTORE_REBUILD;
diff --git a/source/blender/editors/space_outliner/outliner_utils.cc b/source/blender/editors/space_outliner/outliner_utils.cc
index 9c1425befdd..2ce017f4f64 100644
--- a/source/blender/editors/space_outliner/outliner_utils.cc
+++ b/source/blender/editors/space_outliner/outliner_utils.cc
@@ -184,8 +184,7 @@ TreeElement *outliner_find_tse(SpaceOutliner *space_outliner, const TreeStoreEle
}
/* Check if 'tse' is in tree-store. */
- tselem = BKE_outliner_treehash_lookup_any(
- space_outliner->runtime->treehash, tse->type, tse->nr, tse->id);
+ tselem = space_outliner->runtime->tree_hash->lookup_any(tse->type, tse->nr, tse->id);
if (tselem) {
return outliner_find_tree_element(&space_outliner->tree, tselem);
}
diff --git a/source/blender/editors/space_outliner/space_outliner.cc b/source/blender/editors/space_outliner/space_outliner.cc
index 2435e804ed5..66ee0f4f3af 100644
--- a/source/blender/editors/space_outliner/space_outliner.cc
+++ b/source/blender/editors/space_outliner/space_outliner.cc
@@ -38,17 +38,10 @@
#include "tree/tree_display.hh"
SpaceOutliner_Runtime::SpaceOutliner_Runtime(const SpaceOutliner_Runtime & /*other*/)
- : tree_display(nullptr), treehash(nullptr)
+ : tree_display(nullptr), tree_hash(nullptr)
{
}
-SpaceOutliner_Runtime::~SpaceOutliner_Runtime()
-{
- if (treehash) {
- BKE_outliner_treehash_free(treehash);
- }
-}
-
static void outliner_main_region_init(wmWindowManager *wm, ARegion *region)
{
ListBase *lb;
@@ -418,7 +411,7 @@ static void outliner_id_remap(ScrArea *area, SpaceLink *slink, const struct IDRe
/* Note that the Outliner may not be the active editor of the area, and hence not initialized.
* So runtime data might not have been created yet. */
- if (space_outliner->runtime && space_outliner->runtime->treehash && changed) {
+ if (space_outliner->runtime && space_outliner->runtime->tree_hash && changed) {
/* rebuild hash table, because it depends on ids too */
/* postpone a full rebuild because this can be called many times on-free */
space_outliner->storeflag |= SO_TREESTORE_REBUILD;