[Bf-blender-cvs] [7acc8a5a929] master: Depsgraph: Use BLI::Map for RNANodeQuery.id_data_map_

Jacques Lucke noreply at git.blender.org
Tue Apr 28 11:40:17 CEST 2020


Commit: 7acc8a5a929b899bf0c0dd63bda4dd6b9c6c8aed
Author: Jacques Lucke
Date:   Tue Apr 28 11:37:44 2020 +0200
Branches: master
https://developer.blender.org/rB7acc8a5a929b899bf0c0dd63bda4dd6b9c6c8aed

Depsgraph: Use BLI::Map for RNANodeQuery.id_data_map_

Reviewers: sergey

Differential Revision: https://developer.blender.org/D7512

===================================================================

M	source/blender/depsgraph/intern/builder/deg_builder_rna.cc
M	source/blender/depsgraph/intern/builder/deg_builder_rna.h
M	source/blender/depsgraph/intern/depsgraph_type.h

===================================================================

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
index 73f6730be03..8bd3dff482d 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
@@ -121,26 +121,13 @@ bool RNANodeIdentifier::is_valid() const
 
 /* ********************************** Query ********************************* */
 
-namespace {
-
-void ghash_id_data_free_func(void *value)
-{
-  RNANodeQueryIDData *id_data = static_cast<RNANodeQueryIDData *>(value);
-  OBJECT_GUARDED_DELETE(id_data, RNANodeQueryIDData);
-}
-
-}  // namespace
-
 RNANodeQuery::RNANodeQuery(Depsgraph *depsgraph, DepsgraphBuilder *builder)
-    : depsgraph_(depsgraph),
-      builder_(builder),
-      id_data_map_(BLI_ghash_ptr_new("rna node query id data hash"))
+    : depsgraph_(depsgraph), builder_(builder)
 {
 }
 
 RNANodeQuery::~RNANodeQuery()
 {
-  BLI_ghash_free(id_data_map_, nullptr, ghash_id_data_free_func);
 }
 
 Node *RNANodeQuery::find_node(const PointerRNA *ptr,
@@ -384,12 +371,9 @@ RNANodeIdentifier RNANodeQuery::construct_node_identifier(const PointerRNA *ptr,
 
 RNANodeQueryIDData *RNANodeQuery::ensure_id_data(const ID *id)
 {
-  RNANodeQueryIDData **id_data_ptr;
-  if (!BLI_ghash_ensure_p(
-          id_data_map_, const_cast<ID *>(id), reinterpret_cast<void ***>(&id_data_ptr))) {
-    *id_data_ptr = OBJECT_GUARDED_NEW(RNANodeQueryIDData, id);
-  }
-  return *id_data_ptr;
+  unique_ptr<RNANodeQueryIDData> &id_data = id_data_map_.lookup_or_add(
+      id, [&]() { return BLI::make_unique<RNANodeQueryIDData>(id); });
+  return id_data.get();
 }
 
 }  // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_rna.h b/source/blender/depsgraph/intern/builder/deg_builder_rna.h
index 8a79d9abef9..e7e9e883e85 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_rna.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_rna.h
@@ -83,7 +83,7 @@ class RNANodeQuery {
   DepsgraphBuilder *builder_;
 
   /* Indexed by an ID, returns RNANodeQueryIDData associated with that ID. */
-  GHash *id_data_map_;
+  Map<const ID *, unique_ptr<RNANodeQueryIDData>> id_data_map_;
 
   /* Construct identifier of the node which corresponds given configuration
    * of RNA property. */
diff --git a/source/blender/depsgraph/intern/depsgraph_type.h b/source/blender/depsgraph/intern/depsgraph_type.h
index a3dc2135f78..2b8b5471d0f 100644
--- a/source/blender/depsgraph/intern/depsgraph_type.h
+++ b/source/blender/depsgraph/intern/depsgraph_type.h
@@ -58,6 +58,7 @@ using std::map;
 using std::pair;
 using std::set;
 using std::string;
+using std::unique_ptr;
 using std::unordered_map;
 using std::vector;



More information about the Bf-blender-cvs mailing list