Avoid allocation of evaluation context for iterator

Use stack-allocated context when possible.
This commit is contained in:
Sergey Sharybin 2017-06-08 16:11:14 +02:00
parent 2f9cfda459
commit 2335bfeaa0
3 changed files with 10 additions and 11 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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
}