Commit: e355b47740d449036c410891584ee3a5c05a048f
Author: Sergey Sharybin
Date:   Thu May 26 14:33:09 2016 +0200
Branches: depsgraph_cleanup
https://developer.blender.org/rBe355b47740d449036c410891584ee3a5c05a048f

Depsgraph: Use GHash for the id map

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

M       source/blender/depsgraph/intern/builder/deg_builder.cc
M       source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
M       source/blender/depsgraph/intern/depsgraph.cc
M       source/blender/depsgraph/intern/depsgraph.h
M       source/blender/depsgraph/intern/depsgraph_debug.cc
M       source/blender/depsgraph/intern/depsgraph_tag.cc
M       source/blender/depsgraph/util/deg_util_map.h

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

diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc 
b/source/blender/depsgraph/intern/builder/deg_builder.cc
index f9b8768..fddf0e4 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder.cc
@@ -35,6 +35,9 @@
 
 #include "DNA_anim_types.h"
 
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
 #include "intern/depsgraph.h"
 #include "intern/depsgraph_types.h"
 #include "intern/nodes/deg_node.h"
@@ -105,11 +108,9 @@ void deg_graph_build_finalize(Depsgraph *graph)
        }
 
        /* Re-tag IDs for update if it was tagged before the relations update 
tag. */
-       for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
-            it != graph->id_hash.end();
-            ++it)
-       {
-               IDDepsNode *id_node = it->second;
+       GHashIterator gh_iter;
+       GHASH_ITER (gh_iter, graph->id_hash) {
+               IDDepsNode *id_node = reinterpret_cast<IDDepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
                ID *id = id_node->id;
                if (id->tag & LIB_TAG_ID_RECALC_ALL &&
                    id->tag & LIB_TAG_DOIT)
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc 
b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
index dc2328c..2bef309 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
@@ -30,6 +30,9 @@
  * Implementation of tools for debugging the depsgraph
  */
 
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
 extern "C" {
 #include "DNA_listBase.h"
 
@@ -521,11 +524,9 @@ static void deg_debug_graphviz_graph_nodes(const 
DebugContext &ctx,
        if (graph->root_node) {
                deg_debug_graphviz_node(ctx, graph->root_node);
        }
-       for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
-            it != graph->id_hash.end();
-            ++it)
-       {
-               DepsNode *node = it->second;
+       GHashIterator gh_iter;
+       GHASH_ITER (gh_iter, graph->id_hash) {
+               DepsNode *node = reinterpret_cast<DepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
                deg_debug_graphviz_node(ctx, node);
        }
        TimeSourceDepsNode *time_source = graph->find_time_source(NULL);
@@ -537,11 +538,9 @@ static void deg_debug_graphviz_graph_nodes(const 
DebugContext &ctx,
 static void deg_debug_graphviz_graph_relations(const DebugContext &ctx,
                                                const Depsgraph *graph)
 {
-       for (Depsgraph::IDNodeMap::const_iterator it = graph->id_hash.begin();
-            it != graph->id_hash.end();
-            ++it)
-       {
-               IDDepsNode *id_node = it->second;
+       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)
diff --git a/source/blender/depsgraph/intern/depsgraph.cc 
b/source/blender/depsgraph/intern/depsgraph.cc
index 191f68f..b3c26b9 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -36,6 +36,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
 #include "BLI_listbase.h"
 
 extern "C" {
@@ -72,6 +74,7 @@ Depsgraph::Depsgraph()
     layers(0)
 {
        BLI_spin_init(&lock);
+       id_hash = BLI_ghash_ptr_new("depsgraph id hash");
 }
 
 Depsgraph::~Depsgraph()
@@ -79,6 +82,7 @@ Depsgraph::~Depsgraph()
        /* Free root node - it won't have been freed yet... */
        clear_id_nodes();
        clear_subgraph_nodes();
+       BLI_ghash_free(id_hash, NULL, NULL);
        if (this->root_node != NULL) {
                OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode);
        }
@@ -309,8 +313,7 @@ void Depsgraph::clear_subgraph_nodes()
 
 IDDepsNode *Depsgraph::find_id_node(const ID *id) const
 {
-       IDNodeMap::const_iterator it = this->id_hash.find(id);
-       return it != this->id_hash.end() ? it->second : NULL;
+       return reinterpret_cast<IDDepsNode *>(BLI_ghash_lookup(id_hash, id));
 }
 
 IDDepsNode *Depsgraph::add_id_node(ID *id, const string &name)
@@ -321,7 +324,7 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, const string 
&name)
                id_node = (IDDepsNode *)factory->create_node(id, "", name);
                id->tag |= LIB_TAG_DOIT;
                /* register */
-               this->id_hash[id] = id_node;
+               BLI_ghash_insert(id_hash, id, id_node);
        }
        return id_node;
 }
@@ -331,21 +334,19 @@ void Depsgraph::remove_id_node(const ID *id)
        IDDepsNode *id_node = find_id_node(id);
        if (id_node) {
                /* unregister */
-               this->id_hash.erase(id);
+               BLI_ghash_remove(id_hash, id, NULL, NULL);
                OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
        }
 }
 
 void Depsgraph::clear_id_nodes()
 {
-       for (IDNodeMap::const_iterator it = id_hash.begin();
-            it != id_hash.end();
-            ++it)
-       {
-               IDDepsNode *id_node = it->second;
+       GHashIterator gh_iter;
+       GHASH_ITER (gh_iter, id_hash) {
+               IDDepsNode *id_node = reinterpret_cast<IDDepsNode 
*>(BLI_ghashIterator_getValue(&gh_iter));
                OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
        }
-       id_hash.clear();
+       BLI_ghash_clear(id_hash, NULL, NULL);
 }
 
 /* Add new relationship between two nodes. */
@@ -458,7 +459,7 @@ void Depsgraph::clear_all_nodes()
 {
        clear_id_nodes();
        clear_subgraph_nodes();
-       id_hash.clear();
+       BLI_ghash_clear(id_hash, NULL, NULL);
        if (this->root_node) {
                OBJECT_GUARDED_DELETE(this->root_node, RootDepsNode);
                root_node = NULL;
diff --git a/source/blender/depsgraph/intern/depsgraph.h 
b/source/blender/depsgraph/intern/depsgraph.h
index a02ed0c..cd07f3f 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -40,10 +40,10 @@
 
 #include "intern/depsgraph_types.h"
 
-#include "util/deg_util_map.h"
 #include "util/deg_util_set.h"
 
 struct ID;
+struct GHash;
 struct PointerRNA;
 struct PropertyRNA;
 
@@ -96,7 +96,6 @@ struct DepsRelation {
 
 /* Dependency Graph object */
 struct Depsgraph {
-       typedef unordered_map<const ID *, IDDepsNode *> IDNodeMap;
        typedef unordered_set<SubgraphDepsNode *> Subgraphs;
        typedef unordered_set<OperationDepsNode *> EntryTags;
        typedef vector<OperationDepsNode *> OperationNodes;
@@ -165,7 +164,7 @@ struct Depsgraph {
 
        /* <ID : IDDepsNode> mapping from ID blocks to nodes representing these 
blocks
         * (for quick lookups). */
-       IDNodeMap id_hash;
+       GHash *id_hash;
 
        /* "root" node - the one where all evaluation enters from. */
        RootDepsNode *root_node;
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc 
b/source/blender/depsgraph/intern/depsgraph_debug.cc
index 8e86211..615bbf7 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -30,6 +30,9 @@
  * Implementation of tools for debugging the depsgraph
  */
 
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
 extern "C" {
 #include "DNA_scene_types.h"
 
@@ -215,11 +218,9 @@ void DEG_stats_simple(const Depsgraph *graph, size_t 
*r_outer,
                size_t tot_outer = 0;
                size_t tot_rels = 0;
 
-               for (DEG::Depsgraph::IDNodeMap::const_iterator it = 
deg_graph->id_hash.begin();
-                    it != deg_graph->id_hash.end();
-                    ++it)
-               {
-                       DEG::IDDepsNode *id_node = it->second;
+               GHashIterator gh_iter;
+               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();
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc 
b/source/blender/depsgraph/intern/depsgraph_tag.cc
index a5bbfe1..abdffec 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -314,11 +314,9 @@ void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
                 * This is mainly needed on file load only, after that updates 
of invisible objects
                 * will be stored in the pending list.
                 */
-               for (DEG::Depsgraph::IDNodeMap::const_iterator it = 
graph->id_hash.begin();
-                    it != graph->id_hash.end();
-                    ++it)
-               {
-                       DEG::IDDepsNode *id_node = it->second;
+               GHashIterator gh_iter;
+               GHASH_ITER (gh_iter, graph->id_hash) {
+                       DEG::IDDepsNode *id_node = 
reinterpret_cast<DEG::IDDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
                        ID *id = id_node->id;
                        if ((id->tag & LIB_TAG_ID_RECALC_ALL) != 0 ||
                            (id_node->layers & scene->lay_updated) == 0)
diff --git a/source/blender/depsgraph/util/deg_util_map.h 
b/source/blender/depsgraph/util/deg_util_map.h
index fc99835..ffc2160 100644
--- a/source/blender/depsgraph/util/deg_util_map.h
+++ b/source/blender/depsgraph/util/deg_util_map.h
@@ -32,8 +32,8 @@
 
 #include <map>
 
-using std::map;
-using std::pair;
+//using std::map;
+//using std::pair;
 
 #if defined(DEG_NO_UNORDERED_MAP)
 #  include <map>

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

Reply via email to