Commit: 81c3bf448ad76df4c24f7f90ae5b00f971c809e3
Author: Sergey Sharybin
Date:   Thu May 26 15:40:48 2016 +0200
Branches: depsgraph_cleanup
https://developer.blender.org/rB81c3bf448ad76df4c24f7f90ae5b00f971c809e3

Depsgraph: Use GHash for components in ID node

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

M       source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
M       source/blender/depsgraph/intern/depsgraph_debug.cc
M       source/blender/depsgraph/intern/nodes/deg_node.cc
M       source/blender/depsgraph/intern/nodes/deg_node.h

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

diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc 
b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
index 5b6c5c8..a9f2185 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
@@ -365,16 +365,14 @@ static void deg_debug_graphviz_node(const DebugContext 
&ctx,
                case DEPSNODE_TYPE_ID_REF:
                {
                        const IDDepsNode *id_node = (const IDDepsNode *)node;
-                       if (id_node->components.empty()) {
+                       if (BLI_ghash_size(id_node->components) == 0) {
                                deg_debug_graphviz_node_single(ctx, node);
                        }
                        else {
                                deg_debug_graphviz_node_cluster_begin(ctx, 
node);
-                               for (IDDepsNode::ComponentMap::const_iterator 
it = id_node->components.begin();
-                                    it != id_node->components.end();
-                                    ++it)
-                               {
-                                       const ComponentDepsNode *comp = 
it->second;
+                               GHashIterator gh_iter;
+                               GHASH_ITER (gh_iter, id_node->components) {
+                                       const ComponentDepsNode *comp = 
reinterpret_cast<const ComponentDepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
                                        deg_debug_graphviz_node(ctx, comp);
                                }
                                deg_debug_graphviz_node_cluster_end(ctx);
@@ -431,7 +429,7 @@ static bool deg_debug_graphviz_is_cluster(const DepsNode 
*node)
                case DEPSNODE_TYPE_ID_REF:
                {
                        const IDDepsNode *id_node = (const IDDepsNode *)node;
-                       return !id_node->components.empty();
+                       return BLI_ghash_size(id_node->components) > 0;
                }
                case DEPSNODE_TYPE_SUBGRAPH:
                {
@@ -538,14 +536,12 @@ static void deg_debug_graphviz_graph_relations(const 
DebugContext &ctx,
        GHashIterator gh_iter;
        GHASH_ITER (gh_iter, graph->id_hash) {
                IDDepsNode *id_node = reinterpret_cast<IDDepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
-               for (IDDepsNode::ComponentMap::const_iterator it = 
id_node->components.begin();
-                    it != id_node->components.end();
-                    ++it)
-               {
-                       ComponentDepsNode *comp_node = it->second;
-                       GHashIterator gh_iter;
-                       GHASH_ITER (gh_iter, comp_node->operations) {
-                               OperationDepsNode *op_node = 
reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
+               GHashIterator gh_comp_iter;
+               GHASH_ITER (gh_comp_iter, id_node->components) {
+                       ComponentDepsNode *comp_node = 
reinterpret_cast<ComponentDepsNode 
*>(BLI_ghashIterator_getValue(&gh_comp_iter));
+                       GHashIterator gh_op_iter;
+                       GHASH_ITER (gh_op_iter, comp_node->operations) {
+                               OperationDepsNode *op_node = 
reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_op_iter));
                                deg_debug_graphviz_node_relations(ctx, op_node);
                        }
                }
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc 
b/source/blender/depsgraph/intern/depsgraph_debug.cc
index 9d76749..1758b23 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -222,15 +222,13 @@ void DEG_stats_simple(const Depsgraph *graph, size_t 
*r_outer,
                GHASH_ITER (gh_iter, deg_graph->id_hash) {
                        DEG::IDDepsNode *id_node = 
reinterpret_cast<DEG::IDDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
                        tot_outer++;
-                       for (DEG::IDDepsNode::ComponentMap::const_iterator it = 
id_node->components.begin();
-                            it != id_node->components.end();
-                            ++it)
-                       {
-                               DEG::ComponentDepsNode *comp_node = it->second;
+                       GHashIterator gh_comp_iter;
+                       GHASH_ITER (gh_iter, id_node->components) {
+                               DEG::ComponentDepsNode *comp_node = 
reinterpret_cast<DEG::ComponentDepsNode 
*>(BLI_ghashIterator_getValue(&gh_comp_iter));
                                tot_outer++;
-                               GHashIterator gh_iter;
-                               GHASH_ITER (gh_iter, comp_node->operations) {
-                                       DEG::OperationDepsNode *op_node = 
reinterpret_cast<DEG::OperationDepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
+                               GHashIterator gh_op_iter;
+                               GHASH_ITER (gh_op_iter, comp_node->operations) {
+                                       DEG::OperationDepsNode *op_node = 
reinterpret_cast<DEG::OperationDepsNode 
*>(BLI_ghashIterator_getValue(&gh_op_iter));
                                        tot_rels += op_node->inlinks.size();
                                }
                        }
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc 
b/source/blender/depsgraph/intern/nodes/deg_node.cc
index a5e9b2d..94a8e60 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node.cc
@@ -34,6 +34,7 @@
 #include <string.h>
 
 #include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 
 extern "C" {
 #include "DNA_ID.h"
@@ -70,7 +71,7 @@ DepsNode::TypeInfo::TypeInfo(eDepsNode_Type type, const char 
*tname)
 
 DepsNode::DepsNode()
 {
-       this->name[0] = '\0';
+       name[0] = '\0';
 }
 
 DepsNode::~DepsNode()
@@ -140,6 +141,30 @@ static DepsNodeFactoryImpl<TimeSourceDepsNode> 
DNTI_TIMESOURCE;
 
 /* ID Node ================================================ */
 
+static unsigned int id_deps_node_hash_key(const void *key_v)
+{
+    const IDDepsNode::ComponentIDKey *key =
+            reinterpret_cast<const IDDepsNode::ComponentIDKey *>(key_v);
+    return hash_combine(BLI_ghashutil_uinthash(key->type),
+                        BLI_ghashutil_strhash_p(key->name.c_str()));
+}
+
+static bool id_deps_node_hash_key_cmp(const void *a, const void *b)
+{
+    const IDDepsNode::ComponentIDKey *key_a =
+            reinterpret_cast<const IDDepsNode::ComponentIDKey *>(a);
+    const IDDepsNode::ComponentIDKey *key_b =
+            reinterpret_cast<const IDDepsNode::ComponentIDKey *>(b);
+    return !(*key_a == *key_b);
+}
+
+static void id_deps_node_hash_key_free(void *key_v)
+{
+    typedef IDDepsNode::ComponentIDKey ComponentIDKey;
+    ComponentIDKey *key = reinterpret_cast<ComponentIDKey *>(key_v);
+    OBJECT_GUARDED_DELETE(key, ComponentIDKey);
+}
+
 /* Initialize 'id' node - from pointer data given. */
 void IDDepsNode::init(const ID *id, const string &UNUSED(subdata))
 {
@@ -149,6 +174,10 @@ void IDDepsNode::init(const ID *id, const string 
&UNUSED(subdata))
        this->layers = (1 << 20) - 1;
        this->eval_flags = 0;
 
+       components = BLI_ghash_new(id_deps_node_hash_key,
+                                  id_deps_node_hash_key_cmp,
+                                  "depsgraph id components hash");
+
        /* NOTE: components themselves are created if/when needed.
         * This prevents problems with components getting added
         * twice if an ID-Ref needs to be created to house it...
@@ -159,27 +188,27 @@ void IDDepsNode::init(const ID *id, const string 
&UNUSED(subdata))
 IDDepsNode::~IDDepsNode()
 {
        clear_components();
+       BLI_ghash_free(components, id_deps_node_hash_key_free, NULL);
 }
 
 ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
                                               const string &name) const
 {
        ComponentIDKey key(type, name);
-       ComponentMap::const_iterator it = components.find(key);
-       return it != components.end() ? it->second : NULL;
+       return reinterpret_cast<ComponentDepsNode 
*>(BLI_ghash_lookup(components, &key));
 }
 
 ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
                                              const string &name)
 {
-       ComponentIDKey key(type, name);
        ComponentDepsNode *comp_node = find_component(type, name);
        if (!comp_node) {
                DepsNodeFactory *factory = deg_get_node_factory(type);
                comp_node = (ComponentDepsNode *)factory->create_node(this->id, 
"", name);
 
                /* Register. */
-               this->components[key] = comp_node;
+               ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, 
name);
+               BLI_ghash_insert(components, key, comp_node);
                comp_node->owner = this;
        }
        return comp_node;
@@ -187,34 +216,30 @@ ComponentDepsNode 
*IDDepsNode::add_component(eDepsNode_Type type,
 
 void IDDepsNode::remove_component(eDepsNode_Type type, const string &name)
 {
-       ComponentIDKey key(type, name);
        ComponentDepsNode *comp_node = find_component(type, name);
        if (comp_node) {
                /* Unregister. */
-               this->components.erase(key);
+               ComponentIDKey key(type, name);
+               BLI_ghash_remove(components, &key, id_deps_node_hash_key_free, 
NULL);
                OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
        }
 }
 
 void IDDepsNode::clear_components()
 {
-       for (ComponentMap::const_iterator it = components.begin();
-            it != components.end();
-            ++it)
-       {
-               ComponentDepsNode *comp_node = it->second;
+       GHashIterator gh_iter;
+       GHASH_ITER (gh_iter, components) {
+               ComponentDepsNode *comp_node = 
reinterpret_cast<ComponentDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
                OBJECT_GUARDED_DELETE(comp_node, ComponentDepsNode);
        }
-       components.clear();
+       BLI_ghash_clear(components, id_deps_node_hash_key_free, NULL);
 }
 
 void IDDepsNode::tag_update(Depsgraph *graph)
 {
-       for (ComponentMap::const_iterator it = components.begin();
-            it != components.end();
-            ++it)
-       {
-               ComponentDepsNode *comp_node = it->second;
+       GHashIterator gh_iter;
+       GHASH_ITER (gh_iter, components) {
+               ComponentDepsNode *comp_node = 
reinterpret_cast<ComponentDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
                /* TODO(sergey): What about drievrs? */
                bool do_component_tag = comp_node->type != 
DEPSNODE_TYPE_ANIMATION;
                if (comp_node->type == DEPSNODE_TYPE_ANIMATION) {
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.h 
b/source/blender/depsgraph/intern/nodes/deg_node.h
index 2b45769..1092997 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node.h
@@ -37,6 +37,7 @@
 #include "util/deg_util_set.h"
 
 struct ID;
+struct GHash;
 struct Scene;
 
 namespace DEG {
@@ -158,23 +159,6 @@ struct IDDepsNode : public DepsNode {
                string name;
        };
 
-       /* XXX can't specialize std::hash for this purpose, because 
ComponentIDKey is
-        * a nested type ...
-        *
-        *   http://stackoverflow.com/a/951245
-        */
-       struct component_key_hash {
-               bool operator() (const ComponentIDKey &key) const
-               {
-                       return hash_combine(BLI_ghashutil_uinthash(key.type),
-                                           
BLI_ghashutil_strhash_p(key.name.c_str()));
-               }
-       };
-
-       typedef unordered_map<ComponentIDKey,
-                             ComponentDepsNode *,
-                             component_key_hash> ComponentMap;
-
        void init(const ID *id, const string &subdata);
        ~IDDepsNode();
 
@@ -191,7 +175,7 @@ struct IDDepsNode : public DepsNode {
        ID *id;
 
        /* Hash to make it faster to look up components. */
-       ComponentMap components;
+       GHash *component

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to