Depsgraph: Use BLI::Map for RNANodeQuery.id_data_map_

Reviewers: sergey

Differential Revision: https://developer.blender.org/D7512
This commit is contained in:
Jacques Lucke 2020-04-28 11:37:44 +02:00
parent 0372121e17
commit 7acc8a5a92
3 changed files with 6 additions and 21 deletions

View File

@ -121,26 +121,13 @@ bool RNANodeIdentifier::is_valid() const
/* ********************************** Query ********************************* */ /* ********************************** 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) RNANodeQuery::RNANodeQuery(Depsgraph *depsgraph, DepsgraphBuilder *builder)
: depsgraph_(depsgraph), : depsgraph_(depsgraph), builder_(builder)
builder_(builder),
id_data_map_(BLI_ghash_ptr_new("rna node query id data hash"))
{ {
} }
RNANodeQuery::~RNANodeQuery() RNANodeQuery::~RNANodeQuery()
{ {
BLI_ghash_free(id_data_map_, nullptr, ghash_id_data_free_func);
} }
Node *RNANodeQuery::find_node(const PointerRNA *ptr, 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 *RNANodeQuery::ensure_id_data(const ID *id)
{ {
RNANodeQueryIDData **id_data_ptr; unique_ptr<RNANodeQueryIDData> &id_data = id_data_map_.lookup_or_add(
if (!BLI_ghash_ensure_p( id, [&]() { return BLI::make_unique<RNANodeQueryIDData>(id); });
id_data_map_, const_cast<ID *>(id), reinterpret_cast<void ***>(&id_data_ptr))) { return id_data.get();
*id_data_ptr = OBJECT_GUARDED_NEW(RNANodeQueryIDData, id);
}
return *id_data_ptr;
} }
} // namespace DEG } // namespace DEG

View File

@ -83,7 +83,7 @@ class RNANodeQuery {
DepsgraphBuilder *builder_; DepsgraphBuilder *builder_;
/* Indexed by an ID, returns RNANodeQueryIDData associated with that ID. */ /* 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 /* Construct identifier of the node which corresponds given configuration
* of RNA property. */ * of RNA property. */

View File

@ -58,6 +58,7 @@ using std::map;
using std::pair; using std::pair;
using std::set; using std::set;
using std::string; using std::string;
using std::unique_ptr;
using std::unordered_map; using std::unordered_map;
using std::vector; using std::vector;