[Bf-blender-cvs] [b5b87cf] depsgraph_cleanup: Depsgraph: Use GHash for operation nodes stored in component

Sergey Sharybin noreply at git.blender.org
Thu May 26 18:04:00 CEST 2016


Commit: b5b87cf11e962644eec5cfdc7f2edddd2083c982
Author: Sergey Sharybin
Date:   Thu May 26 15:15:55 2016 +0200
Branches: depsgraph_cleanup
https://developer.blender.org/rBb5b87cf11e962644eec5cfdc7f2edddd2083c982

Depsgraph: Use GHash for operation nodes stored in component

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

M	source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
M	source/blender/depsgraph/intern/depsgraph_debug.cc
M	source/blender/depsgraph/intern/eval/deg_eval_flush.cc
M	source/blender/depsgraph/intern/nodes/deg_node_component.cc
M	source/blender/depsgraph/intern/nodes/deg_node_component.h

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

diff --git a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
index 2bef309..5b6c5c8 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_graphviz.cc
@@ -406,13 +406,10 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
 		case DEPSNODE_TYPE_EVAL_PARTICLES:
 		{
 			ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
-			if (!comp_node->operations.empty()) {
-				deg_debug_graphviz_node_cluster_begin(ctx, node);
-				for (ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
-				     it != comp_node->operations.end();
-				     ++it)
-				{
-					const DepsNode *op_node = it->second;
+			if (BLI_ghash_size(comp_node->operations) > 0) {
+				GHashIterator gh_iter;
+				GHASH_ITER (gh_iter, comp_node->operations) {
+					const DepsNode *op_node = reinterpret_cast<const DepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
 					deg_debug_graphviz_node(ctx, op_node);
 				}
 				deg_debug_graphviz_node_cluster_end(ctx);
@@ -451,7 +448,7 @@ static bool deg_debug_graphviz_is_cluster(const DepsNode *node)
 		case DEPSNODE_TYPE_BONE:
 		{
 			ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
-			return !comp_node->operations.empty();
+			return BLI_ghash_size(comp_node->operations) > 0;
 		}
 		default:
 			return false;
@@ -546,11 +543,9 @@ static void deg_debug_graphviz_graph_relations(const DebugContext &ctx,
 		     ++it)
 		{
 			ComponentDepsNode *comp_node = it->second;
-			for (ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
-			     it != comp_node->operations.end();
-			     ++it)
-			{
-				OperationDepsNode *op_node = it->second;
+			GHashIterator gh_iter;
+			GHASH_ITER (gh_iter, comp_node->operations) {
+				OperationDepsNode *op_node = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_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 615bbf7..9d76749 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -228,11 +228,9 @@ void DEG_stats_simple(const Depsgraph *graph, size_t *r_outer,
 			{
 				DEG::ComponentDepsNode *comp_node = it->second;
 				tot_outer++;
-				for (DEG::ComponentDepsNode::OperationMap::const_iterator it = comp_node->operations.begin();
-				     it != comp_node->operations.end();
-				     ++it)
-				{
-					DEG::OperationDepsNode *op_node = it->second;
+				GHashIterator gh_iter;
+				GHASH_ITER (gh_iter, comp_node->operations) {
+					DEG::OperationDepsNode *op_node = reinterpret_cast<DEG::OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
 					tot_rels += op_node->inlinks.size();
 				}
 			}
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
index 8261966..cb2cb34 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
@@ -177,11 +177,9 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
 		 */
 		ComponentDepsNode *component = node->owner;
 		if ((component->flags & DEPSCOMP_FULLY_SCHEDULED) == 0) {
-			for (ComponentDepsNode::OperationMap::iterator it = component->operations.begin();
-			     it != node->owner->operations.end();
-			     ++it)
-			{
-				OperationDepsNode *op = it->second;
+			GHashIterator gh_iter;
+			GHASH_ITER (gh_iter, component->operations) {
+				OperationDepsNode *op = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
 				op->flag |= DEPSOP_FLAG_NEEDS_UPDATE;
 			}
 			component->flags |= DEPSCOMP_FULLY_SCHEDULED;
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
index a393874..4bc5c45 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
@@ -51,11 +51,38 @@ namespace DEG {
 
 /* Standard Component Methods ============================= */
 
+static unsigned int comp_node_hash_key(const void *key_v)
+{
+	const ComponentDepsNode::OperationIDKey *key =
+	        reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(key_v);
+	return hash_combine(BLI_ghashutil_uinthash(key->opcode),
+	                    BLI_ghashutil_strhash_p(key->name.c_str()));
+}
+
+static bool comp_node_hash_key_cmp(const void *a, const void *b)
+{
+	const ComponentDepsNode::OperationIDKey *key_a =
+	        reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(a);
+	const ComponentDepsNode::OperationIDKey *key_b =
+	        reinterpret_cast<const ComponentDepsNode::OperationIDKey *>(b);
+	return !(*key_a == *key_b);
+}
+
+static void comp_node_hash_key_free(void *key_v)
+{
+	typedef ComponentDepsNode::OperationIDKey OperationIDKey;
+	OperationIDKey *key = reinterpret_cast<OperationIDKey *>(key_v);
+	OBJECT_GUARDED_DELETE(key, OperationIDKey);
+}
+
 ComponentDepsNode::ComponentDepsNode() :
     entry_operation(NULL),
     exit_operation(NULL),
     flags(0)
 {
+	operations = BLI_ghash_new(comp_node_hash_key,
+	                           comp_node_hash_key_cmp,
+	                           "depsgraph id hash");
 }
 
 /* Initialize 'component' node - from pointer data given */
@@ -70,6 +97,7 @@ void ComponentDepsNode::init(const ID * /*id*/,
 ComponentDepsNode::~ComponentDepsNode()
 {
 	clear_operations();
+	BLI_ghash_free(operations, comp_node_hash_key_free, NULL);
 }
 
 string ComponentDepsNode::identifier() const
@@ -84,10 +112,9 @@ string ComponentDepsNode::identifier() const
 
 OperationDepsNode *ComponentDepsNode::find_operation(OperationIDKey key) const
 {
-	OperationMap::const_iterator it = this->operations.find(key);
-
-	if (it != this->operations.end()) {
-		return it->second;
+	OperationDepsNode *node = reinterpret_cast<OperationDepsNode *>(BLI_ghash_lookup(operations, &key));
+	if (node != NULL) {
+		return node;
 	}
 	else {
 		fprintf(stderr, "%s: find_operation(%s) failed\n",
@@ -105,11 +132,7 @@ OperationDepsNode *ComponentDepsNode::find_operation(eDepsOperation_Code opcode,
 
 OperationDepsNode *ComponentDepsNode::has_operation(OperationIDKey key) const
 {
-	OperationMap::const_iterator it = this->operations.find(key);
-	if (it != this->operations.end()) {
-		return it->second;
-	}
-	return NULL;
+	return reinterpret_cast<OperationDepsNode *>(BLI_ghash_lookup(operations, &key));
 }
 
 OperationDepsNode *ComponentDepsNode::has_operation(eDepsOperation_Code opcode,
@@ -127,8 +150,8 @@ OperationDepsNode *ComponentDepsNode::add_operation(eDepsOperation_Type optype,
 		op_node = (OperationDepsNode *)factory->create_node(this->owner->id, "", name);
 
 		/* register opnode in this component's operation set */
-		OperationIDKey key(opcode, name);
-		this->operations[key] = op_node;
+		OperationIDKey *key = OBJECT_GUARDED_NEW(OperationIDKey, opcode, name);
+		BLI_ghash_insert(operations, key, op_node);
 
 		/* set as entry/exit node of component (if appropriate) */
 		if (optype == DEPSOP_TYPE_INIT) {
@@ -164,18 +187,20 @@ void ComponentDepsNode::remove_operation(eDepsOperation_Code opcode, const strin
 	OperationDepsNode *op_node = find_operation(opcode, name);
 	if (op_node) {
 		/* unregister */
-		this->operations.erase(OperationIDKey(opcode, name));
+		OperationIDKey key(opcode, name);
+		BLI_ghash_remove(operations, &key, comp_node_hash_key_free, NULL);
 		OBJECT_GUARDED_DELETE(op_node, OperationDepsNode);
 	}
 }
 
 void ComponentDepsNode::clear_operations()
 {
-	for (OperationMap::const_iterator it = operations.begin(); it != operations.end(); ++it) {
-		OperationDepsNode *op_node = it->second;
+	GHashIterator gh_iter;
+	GHASH_ITER (gh_iter, operations) {
+		OperationDepsNode *op_node = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
 		OBJECT_GUARDED_DELETE(op_node, OperationDepsNode);
 	}
-	operations.clear();
+	BLI_ghash_clear(operations, comp_node_hash_key_free, NULL);
 }
 
 void ComponentDepsNode::tag_update(Depsgraph *graph)
@@ -184,27 +209,48 @@ void ComponentDepsNode::tag_update(Depsgraph *graph)
 	if (entry_op != NULL && entry_op->flag & DEPSOP_FLAG_NEEDS_UPDATE) {
 		return;
 	}
-	for (OperationMap::const_iterator it = operations.begin(); it != operations.end(); ++it) {
-		OperationDepsNode *op_node = it->second;
+	GHashIterator gh_iter;
+	GHASH_ITER (gh_iter, operations) {
+		OperationDepsNode *op_node = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
 		op_node->tag_update(graph);
 	}
 }
 
 OperationDepsNode *ComponentDepsNode::get_entry_operation()
 {
-	if (entry_operation)
+	if (entry_operation) {
 		return entry_operation;
-	else if (operations.size() == 1)
-		return operations.begin()->second;
+	}
+	else if (BLI_ghash_size(operations) == 1) {
+		OperationDepsNode *op_node = NULL;
+		/* TODO(sergey): This is somewhat slow. */
+		GHashIterator gh_iter;
+		GHASH_ITER (gh_iter, operations) {
+			op_node = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
+		}
+		/* Cache for the subsequent usage. */
+		entry_operation = op_node;
+		return op_node;
+	}
 	return NULL;
 }
 
 OperationDepsNode *ComponentDepsNode::get_exit_operation()
 {
-	if (exit_operation)
+	if (exit_operation) {
 		return exit_operation;
-	else if (operations.size() == 1)
-		return operations.begin()->second;
+	}
+	else if (BLI_ghash_size(operations) == 1) {
+		OperationDepsNode *op_node = NULL;
+		/* TODO(sergey): This is somewhat slow. */
+		GHashIterator gh_iter;
+		GHASH_ITER (gh_iter, operations) {
+			op_node = reinterpret_cast<OperationDepsNode *>(BLI_ghashIterator_getValue(&gh_iter));
+		}
+		/* Cache for the subsequent usage. */
+		exit_operation = op_node;
+		return op_node;
+	}
 	return NULL;
 }
 
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h
index d6d3a9c..b41aed6 100644
--- a/source/blender/depsgraph/intern/nodes

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list