[Bf-blender-cvs] [2335bfeaa09] blender2.8: Avoid allocation of evaluation context for iterator

Sergey Sharybin noreply at git.blender.org
Thu Jun 8 16:11:37 CEST 2017


Commit: 2335bfeaa09ff0c700c8c2dc3b388175f2416601
Author: Sergey Sharybin
Date:   Thu Jun 8 16:11:14 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB2335bfeaa09ff0c700c8c2dc3b388175f2416601

Avoid allocation of evaluation context for iterator

Use stack-allocated context when possible.

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

M	source/blender/depsgraph/DEG_depsgraph_query.h
M	source/blender/depsgraph/intern/depsgraph_eval.cc
M	source/blender/depsgraph/intern/depsgraph_query.cc

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

diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index 888730552e9..649e788a0ef 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -33,6 +33,8 @@
 #ifndef __DEG_DEPSGRAPH_QUERY_H__
 #define __DEG_DEPSGRAPH_QUERY_H__
 
+#include "DEG_depsgraph.h"
+
 struct ID;
 
 struct Base;
@@ -74,7 +76,7 @@ enum {
 typedef struct DEGObjectsIteratorData {
 	struct Depsgraph *graph;
 	struct Scene *scene;
-	struct EvaluationContext *eval_ctx;
+	struct EvaluationContext eval_ctx;
 
 	/* TODO(sergey): Base should never be a thing coming FROM depsgraph. */
 	struct Base *base;
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index 62d591f65de..73a0428c264 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -61,7 +61,7 @@ EvaluationContext *DEG_evaluation_context_new(int mode)
 	EvaluationContext *eval_ctx =
 		(EvaluationContext *)MEM_callocN(sizeof(EvaluationContext),
 		                                 "EvaluationContext");
-	eval_ctx->mode = mode;
+	DEG_evaluation_context_init(eval_ctx, mode);
 	return eval_ctx;
 }
 
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index 8022a11818a..bcfcbb3856c 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -111,8 +111,7 @@ void DEG_objects_iterator_begin(BLI_Iterator *iter, DEGObjectsIteratorData *data
 	iter->valid = true;
 
 	data->scene = DEG_get_scene(graph);
-	/* TODO(sergey): Make it in-place initilization of evaluation context. */
-	data->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
+	DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_RENDER);
 
 	/* TODO(sergey): It's really confusing to store pointer to a local data. */
 	Base base = {(Base *)scene_layer->object_bases.first, NULL};
@@ -210,7 +209,7 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
 
 			if ((data->flag & DEG_OBJECT_ITER_FLAG_DUPLI) && (ob->transflag & OB_DUPLI)) {
 				data->dupli_parent = ob;
-				data->dupli_list = object_duplilist(data->eval_ctx, data->scene, ob);
+				data->dupli_list = object_duplilist(&data->eval_ctx, data->scene, ob);
 				data->dupli_object_next = (DupliObject *)data->dupli_list->first;
 			}
 			return;
@@ -240,13 +239,11 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
 
 void DEG_objects_iterator_end(BLI_Iterator *iter)
 {
+#ifndef NDEBUG
 	DEGObjectsIteratorData *data = (DEGObjectsIteratorData *)iter->data;
-	if (data->eval_ctx != NULL) {
-		DEG_evaluation_context_free(data->eval_ctx);
-	}
-
-#ifdef DEBUG
 	/* Force crash in case the iterator data is referenced and accessed down the line. (T51718) */
-	memset(&data->temp_dupli_object, 0xFF, sizeof(data->temp_dupli_object));
+	memset(&data->temp_dupli_object, 0xff, sizeof(data->temp_dupli_object));
+#else
+	(void) iter;
 #endif
 }




More information about the Bf-blender-cvs mailing list