[Bf-blender-cvs] [cec629a] master: Depsgraph: Simplify some loops using foreach()

Sergey Sharybin noreply at git.blender.org
Wed May 25 14:10:48 CEST 2016


Commit: cec629ae425d3e2f37f1b0d7ecda84a4233e5438
Author: Sergey Sharybin
Date:   Wed May 25 13:51:35 2016 +0200
Branches: master
https://developer.blender.org/rBcec629ae425d3e2f37f1b0d7ecda84a4233e5438

Depsgraph: Simplify some loops using foreach()

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

M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph_build.cc
M	source/blender/depsgraph/intern/depsgraph_debug.cc
M	source/blender/depsgraph/intern/depsgraph_eval.cc
M	source/blender/depsgraph/intern/depsgraph_tag.cc
M	source/blender/depsgraph/intern/depsnode.cc
A	source/blender/depsgraph/util/depsgraph_util_foreach.h

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

diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index d293d03..87dbb23 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -55,6 +55,7 @@ extern "C" {
 #include "depsnode_operation.h"
 #include "depsnode_component.h"
 #include "depsgraph_intern.h"
+#include "depsgraph_util_foreach.h"
 
 static DEG_EditorUpdateIDCb deg_editor_update_id_cb = NULL;
 static DEG_EditorUpdateSceneCb deg_editor_update_scene_cb = NULL;
@@ -295,11 +296,7 @@ void Depsgraph::remove_subgraph_node(SubgraphDepsNode *subgraph_node)
 
 void Depsgraph::clear_subgraph_nodes()
 {
-	for (Subgraphs::iterator it = subgraphs.begin();
-	     it != subgraphs.end();
-	     ++it)
-	{
-		SubgraphDepsNode *subgraph_node = *it;
+	foreach (SubgraphDepsNode *subgraph_node, subgraphs) {
 		OBJECT_GUARDED_DELETE(subgraph_node, SubgraphDepsNode);
 	}
 	subgraphs.clear();
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 877ce6e..fed1433 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -100,6 +100,7 @@ extern "C" {
 #include "depsgraph_intern.h"
 
 #include "depsgraph_util_cycle.h"
+#include "depsgraph_util_foreach.h"
 #include "depsgraph_util_transitive.h"
 
 /* ****************** */
@@ -184,18 +185,10 @@ static void deg_graph_build_finalize(Depsgraph *graph)
 {
 	std::stack<OperationDepsNode *> stack;
 
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
+	foreach (OperationDepsNode *node, graph->operations) {
 		node->done = 0;
 		node->num_links_pending = 0;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin();
-		     it_rel != node->inlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
+		foreach (DepsRelation *rel, node->inlinks) {
 			if ((rel->from->type == DEPSNODE_TYPE_OPERATION) &&
 			    (rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
 			{
@@ -212,11 +205,7 @@ static void deg_graph_build_finalize(Depsgraph *graph)
 	while (!stack.empty()) {
 		OperationDepsNode *node = stack.top();
 		if (node->done == 0 && node->outlinks.size() != 0) {
-			for (OperationDepsNode::Relations::const_iterator it_rel = node->outlinks.begin();
-			     it_rel != node->outlinks.end();
-			     ++it_rel)
-			{
-				DepsRelation *rel = *it_rel;
+			foreach (DepsRelation *rel, node->outlinks) {
 				if (rel->to->type == DEPSNODE_TYPE_OPERATION) {
 					OperationDepsNode *to = (OperationDepsNode *)rel->to;
 					if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
@@ -233,11 +222,7 @@ static void deg_graph_build_finalize(Depsgraph *graph)
 		else {
 			stack.pop();
 			IDDepsNode *id_node = node->owner->owner;
-			for (OperationDepsNode::Relations::const_iterator it_rel = node->outlinks.begin();
-			     it_rel != node->outlinks.end();
-			     ++it_rel)
-			{
-				DepsRelation *rel = *it_rel;
+			foreach (DepsRelation *rel, node->outlinks) {
 				if (rel->to->type == DEPSNODE_TYPE_OPERATION) {
 					OperationDepsNode *to = (OperationDepsNode *)rel->to;
 					IDDepsNode *id_to = to->owner->owner;
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc
index efb3e33..5d21eff 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -55,6 +55,7 @@ extern "C" {
 #include "depsnode_component.h"
 #include "depsnode_operation.h"
 #include "depsgraph_intern.h"
+#include "depsgraph_util_foreach.h"
 
 /* ****************** */
 /* Graphviz Debugging */
@@ -1018,33 +1019,18 @@ bool DEG_debug_scene_relations_validate(Main *bmain,
 bool DEG_debug_consistency_check(Depsgraph *graph)
 {
 	/* Validate links exists in both directions. */
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->outlinks.begin();
-		     it_rel != node->outlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
-
+	foreach (OperationDepsNode *node, graph->operations) {
+		foreach (DepsRelation *rel, node->outlinks) {
 			int counter1 = 0;
-			for (OperationDepsNode::Relations::const_iterator tmp_rel = node->outlinks.begin();
-			     tmp_rel != node->outlinks.end();
-			     ++tmp_rel)
-			{
-				if (*tmp_rel == rel) {
+			foreach (DepsRelation *tmp_rel, node->outlinks) {
+				if (tmp_rel == rel) {
 					++counter1;
 				}
 			}
 
 			int counter2 = 0;
-			for (OperationDepsNode::Relations::const_iterator tmp_rel = rel->to->inlinks.begin();
-			     tmp_rel != rel->to->inlinks.end();
-			     ++tmp_rel)
-			{
-				if (*tmp_rel == rel) {
+			foreach (DepsRelation *tmp_rel, rel->to->inlinks) {
+				if (tmp_rel == rel) {
 					++counter2;
 				}
 			}
@@ -1057,33 +1043,18 @@ bool DEG_debug_consistency_check(Depsgraph *graph)
 		}
 	}
 
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin();
-		     it_rel != node->inlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
-
+	foreach (OperationDepsNode *node, graph->operations) {
+		foreach (DepsRelation *rel, node->inlinks) {
 			int counter1 = 0;
-			for (OperationDepsNode::Relations::const_iterator tmp_rel = node->inlinks.begin();
-			     tmp_rel != node->inlinks.end();
-			     ++tmp_rel)
-			{
-				if (*tmp_rel == rel) {
+			foreach (DepsRelation *tmp_rel, node->inlinks) {
+				if (tmp_rel == rel) {
 					++counter1;
 				}
 			}
 
 			int counter2 = 0;
-			for (OperationDepsNode::Relations::const_iterator tmp_rel = rel->from->outlinks.begin();
-			     tmp_rel != rel->from->outlinks.end();
-			     ++tmp_rel)
-			{
-				if (*tmp_rel == rel) {
+			foreach (DepsRelation *tmp_rel, rel->from->outlinks) {
+				if (tmp_rel == rel) {
 					++counter2;
 				}
 			}
@@ -1096,30 +1067,18 @@ bool DEG_debug_consistency_check(Depsgraph *graph)
 	}
 
 	/* Validate node valency calculated in both directions. */
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
+	foreach (OperationDepsNode *node, graph->operations) {
 		node->num_links_pending = 0;
 		node->done = 0;
 	}
 
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
+	foreach (OperationDepsNode *node, graph->operations) {
 		if (node->done) {
 			printf("Node %s is twice in the operations!\n",
 			       node->identifier().c_str());
 			return false;
 		}
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->outlinks.begin();
-		     it_rel != node->outlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
+		foreach (DepsRelation *rel, node->outlinks) {
 			if (rel->to->type == DEPSNODE_TYPE_OPERATION) {
 				OperationDepsNode *to = (OperationDepsNode *)rel->to;
 				BLI_assert(to->num_links_pending < to->inlinks.size());
@@ -1129,17 +1088,9 @@ bool DEG_debug_consistency_check(Depsgraph *graph)
 		node->done = 1;
 	}
 
-	for (Depsgraph::OperationNodes::const_iterator it_op = graph->operations.begin();
-	     it_op != graph->operations.end();
-	     ++it_op)
-	{
-		OperationDepsNode *node = *it_op;
+	foreach (OperationDepsNode *node, graph->operations) {
 		int num_links_pending = 0;
-		for (OperationDepsNode::Relations::const_iterator it_rel = node->inlinks.begin();
-		     it_rel != node->inlinks.end();
-		     ++it_rel)
-		{
-			DepsRelation *rel = *it_rel;
+		foreach (DepsRelation *rel, node->inlinks) {
 			if (rel->from->type == DEPSNODE_TYPE_OPERATION) {
 				++num_links_pending;
 			}
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index 66535f5..e584e8a 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -51,6 +51,7 @@ extern "C" {
 #include "depsnode_component.h"
 #include "depsnode_operation.h"
 #include "depsgraph_debug.h"
+#include "depsgraph_util_foreach.h"
 
 #ifdef WITH_LEGACY_DEPSGRAPH
 static bool use_legacy_depsgraph = true;
@@ -302,11 +303,7 @@ static void calculate_eval_priority(OperationDepsNode *node)
 		/* NOOP nodes have no cost */
 		node->eval_priority = node->is_noop() ? cost : 0.0f;
 
-		for (OperationDepsNode::Relations::const_iterator it = node->outlinks.begin();
-		     it != node->outlinks.end();
-		     ++it)
-		{
-			DepsRelation *rel = *it;
+		foreach (DepsRelation *rel, node->outlinks) {
 			OperationDepsNode *to = (OperationDepsNode *)rel->to;
 			BLI_assert(to->type == DEPSNODE_TYPE_OPERATION);
 			calculate_eval_priority(to);
@@ -362,11 +359,7 @@ static void schedule_graph(TaskPool *pool,
                            Depsgraph *graph,
                            const int layers)
 {
-	for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
-	     it != graph->operations.end();
-	     ++it)
-	{
-		OperationDepsNode *node = *it;
+	foreach (OperationDepsNode *node, graph->operations) {
 		schedule_node(pool, graph, layers, node, false, 0);
 	}
 }
@@ -429,21 +422,13 @@ void DEG_evaluate_on_refresh_ex(EvaluationContext *eval_ctx,
 	calculate_pending_parents(graph, layers);
 
 	/* Clear tags. */
-	for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
-	     it != graph->operations.end();
-	     ++it)
-	{
-		OperationDepsNode *node = *it;
+	foreach (OperationDepsNode *node, graph->operations) {
 		node->done = 0;
 	}
 
 	/* Calculate priority for operation nodes. */
 #ifdef USE_EVAL_PRIORITY
-	for (Depsgraph::OperationNodes::const_iterator it = graph->operations.begin();
-	     it != gr

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list