RNA: optimization to avoid malloc for iterators.
This mostly helps making Cycles scene synchronization a bit faster.
This commit is contained in:
@@ -236,12 +236,40 @@ typedef enum PropertyFlag {
|
||||
PROP_ENUM_NO_TRANSLATE = (1 << 29), /* for enums not to be translated (e.g. renderlayers' names in nodes) */
|
||||
} PropertyFlag;
|
||||
|
||||
struct CollectionPropertyIterator;
|
||||
struct Link;
|
||||
typedef int (*IteratorSkipFunc)(struct CollectionPropertyIterator *iter, void *data);
|
||||
|
||||
typedef struct ListBaseIterator {
|
||||
struct Link *link;
|
||||
int flag;
|
||||
IteratorSkipFunc skip;
|
||||
} ListBaseIterator;
|
||||
|
||||
typedef struct ArrayIterator {
|
||||
char *ptr;
|
||||
char *endptr; /* past the last valid pointer, only for comparisons, ignores skipped values */
|
||||
void *free_ptr; /* will be freed if set */
|
||||
int itemsize;
|
||||
|
||||
/* array length with no skip functions applied, take care not to compare against index from animsys
|
||||
* or python indices */
|
||||
int length;
|
||||
|
||||
/* optional skip function, when set the array as viewed by rna can contain only a subset of the members.
|
||||
* this changes indices so quick array index lookups are not possible when skip function is used. */
|
||||
IteratorSkipFunc skip;
|
||||
} ArrayIterator;
|
||||
|
||||
typedef struct CollectionPropertyIterator {
|
||||
/* internal */
|
||||
PointerRNA parent;
|
||||
PointerRNA builtin_parent;
|
||||
struct PropertyRNA *prop;
|
||||
void *internal;
|
||||
union {
|
||||
ArrayIterator array;
|
||||
ListBaseIterator listbase;
|
||||
} internal;
|
||||
int idprop;
|
||||
int level;
|
||||
|
||||
|
||||
@@ -1147,7 +1147,7 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
|
||||
fprintf(f, " if (iter.valid) {\n");
|
||||
|
||||
if (strcmp(nextfunc, "rna_iterator_array_next") == 0) {
|
||||
fprintf(f, " ArrayIterator *internal = iter.internal;\n");
|
||||
fprintf(f, " ArrayIterator *internal = &iter.internal.array;\n");
|
||||
fprintf(f, " if (index < 0 || index >= internal->length) {\n");
|
||||
fprintf(f, "#ifdef __GNUC__\n");
|
||||
fprintf(f, " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
|
||||
@@ -1167,7 +1167,7 @@ static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, Property
|
||||
fprintf(f, " }\n");
|
||||
}
|
||||
else if (strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
|
||||
fprintf(f, " ListBaseIterator *internal = iter.internal;\n");
|
||||
fprintf(f, " ListBaseIterator *internal = &iter.internal.listbase;\n");
|
||||
fprintf(f, " if (internal->skip) {\n");
|
||||
fprintf(f, " while (index-- > 0 && iter.valid) {\n");
|
||||
fprintf(f, " rna_iterator_listbase_next(&iter);\n");
|
||||
|
||||
@@ -2886,7 +2886,7 @@ void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num)
|
||||
|
||||
if (num > 1 && (iter->idprop || (cprop->property.flag & PROP_RAW_ARRAY))) {
|
||||
/* fast skip for array */
|
||||
ArrayIterator *internal = iter->internal;
|
||||
ArrayIterator *internal = &iter->internal.array;
|
||||
|
||||
if (!internal->skip) {
|
||||
internal->ptr += internal->itemsize * (num - 1);
|
||||
@@ -3227,7 +3227,7 @@ int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, Proper
|
||||
|
||||
if (iter.valid) {
|
||||
/* get data from array iterator and item property */
|
||||
internal = iter.internal;
|
||||
internal = &iter.internal.array;
|
||||
arrayp = (iter.valid) ? iter.ptr.data : NULL;
|
||||
|
||||
if (internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) {
|
||||
@@ -3644,13 +3644,11 @@ int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, Proper
|
||||
|
||||
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
|
||||
{
|
||||
ListBaseIterator *internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
internal = MEM_callocN(sizeof(ListBaseIterator), "ListBaseIterator");
|
||||
internal->link = (lb) ? lb->first : NULL;
|
||||
internal->skip = skip;
|
||||
|
||||
iter->internal = internal;
|
||||
iter->valid = (internal->link != NULL);
|
||||
|
||||
if (skip && iter->valid && skip(iter, internal->link))
|
||||
@@ -3659,7 +3657,7 @@ void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb,
|
||||
|
||||
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
if (internal->skip) {
|
||||
do {
|
||||
@@ -3675,15 +3673,13 @@ void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
|
||||
|
||||
void *rna_iterator_listbase_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
return internal->link;
|
||||
}
|
||||
|
||||
void rna_iterator_listbase_end(CollectionPropertyIterator *iter)
|
||||
void rna_iterator_listbase_end(CollectionPropertyIterator *UNUSED(iter))
|
||||
{
|
||||
MEM_freeN(iter->internal);
|
||||
iter->internal = NULL;
|
||||
}
|
||||
|
||||
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index)
|
||||
@@ -3704,7 +3700,7 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i
|
||||
itemsize = 0;
|
||||
}
|
||||
|
||||
internal = MEM_callocN(sizeof(ArrayIterator), "ArrayIterator");
|
||||
internal = &iter->internal.array;
|
||||
internal->ptr = ptr;
|
||||
internal->free_ptr = free_ptr ? ptr : NULL;
|
||||
internal->endptr = ((char *)ptr) + length * itemsize;
|
||||
@@ -3712,7 +3708,6 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i
|
||||
internal->skip = skip;
|
||||
internal->length = length;
|
||||
|
||||
iter->internal = internal;
|
||||
iter->valid = (internal->ptr != internal->endptr);
|
||||
|
||||
if (skip && iter->valid && skip(iter, internal->ptr))
|
||||
@@ -3721,7 +3716,7 @@ void rna_iterator_array_begin(CollectionPropertyIterator *iter, void *ptr, int i
|
||||
|
||||
void rna_iterator_array_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ArrayIterator *internal = iter->internal;
|
||||
ArrayIterator *internal = &iter->internal.array;
|
||||
|
||||
if (internal->skip) {
|
||||
do {
|
||||
@@ -3737,14 +3732,14 @@ void rna_iterator_array_next(CollectionPropertyIterator *iter)
|
||||
|
||||
void *rna_iterator_array_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ArrayIterator *internal = iter->internal;
|
||||
ArrayIterator *internal = &iter->internal.array;
|
||||
|
||||
return internal->ptr;
|
||||
}
|
||||
|
||||
void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ArrayIterator *internal = iter->internal;
|
||||
ArrayIterator *internal = &iter->internal.array;
|
||||
|
||||
/* for ** arrays */
|
||||
return *(void **)(internal->ptr);
|
||||
@@ -3752,14 +3747,12 @@ void *rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
|
||||
|
||||
void rna_iterator_array_end(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ArrayIterator *internal = iter->internal;
|
||||
ArrayIterator *internal = &iter->internal.array;
|
||||
|
||||
if (internal->free_ptr) {
|
||||
MEM_freeN(internal->free_ptr);
|
||||
internal->free_ptr = NULL;
|
||||
}
|
||||
MEM_freeN(iter->internal);
|
||||
iter->internal = NULL;
|
||||
}
|
||||
|
||||
PointerRNA rna_array_lookup_int(PointerRNA *ptr, StructRNA *type, void *data, int itemsize, int length, int index)
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
static void rna_ActionGroup_channels_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
FCurve *fcu = (FCurve *)internal->link;
|
||||
bActionGroup *grp = fcu->grp;
|
||||
|
||||
|
||||
@@ -441,7 +441,7 @@ static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, Po
|
||||
|
||||
static void rna_Armature_bones_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
Bone *bone = (Bone *)internal->link;
|
||||
|
||||
if (bone->childbase.first)
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
/* we are actually iterating a GroupObject list, so override get */
|
||||
return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject *)internal->link)->ob);
|
||||
|
||||
@@ -355,35 +355,12 @@ int rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, Point
|
||||
|
||||
/* Iterators */
|
||||
|
||||
typedef int (*IteratorSkipFunc)(struct CollectionPropertyIterator *iter, void *data);
|
||||
|
||||
typedef struct ListBaseIterator {
|
||||
Link *link;
|
||||
int flag;
|
||||
IteratorSkipFunc skip;
|
||||
} ListBaseIterator;
|
||||
|
||||
void rna_iterator_listbase_begin(struct CollectionPropertyIterator *iter, struct ListBase *lb, IteratorSkipFunc skip);
|
||||
void rna_iterator_listbase_next(struct CollectionPropertyIterator *iter);
|
||||
void *rna_iterator_listbase_get(struct CollectionPropertyIterator *iter);
|
||||
void rna_iterator_listbase_end(struct CollectionPropertyIterator *iter);
|
||||
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, struct ListBase *lb, int index);
|
||||
|
||||
typedef struct ArrayIterator {
|
||||
char *ptr;
|
||||
char *endptr; /* past the last valid pointer, only for comparisons, ignores skipped values */
|
||||
void *free_ptr; /* will be freed if set */
|
||||
int itemsize;
|
||||
|
||||
/* array length with no skip functions applied, take care not to compare against index from animsys
|
||||
* or python indices */
|
||||
int length;
|
||||
|
||||
/* optional skip function, when set the array as viewed by rna can contain only a subset of the members.
|
||||
* this changes indices so quick array index lookups are not possible when skip function is used. */
|
||||
IteratorSkipFunc skip;
|
||||
} ArrayIterator;
|
||||
|
||||
void rna_iterator_array_begin(struct CollectionPropertyIterator *iter, void *ptr, int itemsize, int length,
|
||||
bool free_ptr, IteratorSkipFunc skip);
|
||||
void rna_iterator_array_next(struct CollectionPropertyIterator *iter);
|
||||
|
||||
@@ -253,7 +253,7 @@ static void rna_inheritance_functions_listbase_next(CollectionPropertyIterator *
|
||||
|
||||
static void rna_Struct_properties_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
IDProperty *group;
|
||||
|
||||
if (internal->flag) {
|
||||
@@ -271,7 +271,7 @@ static void rna_Struct_properties_next(CollectionPropertyIterator *iter)
|
||||
if (group) {
|
||||
rna_iterator_listbase_end(iter);
|
||||
rna_iterator_listbase_begin(iter, &group->data.group, rna_idproperty_known);
|
||||
internal = iter->internal;
|
||||
internal = &iter->internal.listbase;
|
||||
internal->flag = 1;
|
||||
}
|
||||
}
|
||||
@@ -295,7 +295,7 @@ static void rna_Struct_properties_begin(CollectionPropertyIterator *iter, Pointe
|
||||
|
||||
static PointerRNA rna_Struct_properties_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
/* we return either PropertyRNA* or IDProperty*, the rna_access.c
|
||||
* functions can handle both as PropertyRNA* with some tricks */
|
||||
@@ -324,7 +324,7 @@ static void rna_Struct_functions_begin(CollectionPropertyIterator *iter, Pointer
|
||||
|
||||
static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
/* we return either PropertyRNA* or IDProperty*, the rna_access.c
|
||||
* functions can handle both as PropertyRNA* with some tricks */
|
||||
|
||||
@@ -357,7 +357,7 @@ static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key
|
||||
|
||||
static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
|
||||
/* we are actually iterating a Base list, so override get */
|
||||
return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((Base *)internal->link)->object);
|
||||
@@ -664,7 +664,7 @@ static void rna_Scene_all_keyingsets_begin(CollectionPropertyIterator *iter, Poi
|
||||
|
||||
static void rna_Scene_all_keyingsets_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
KeyingSet *ks = (KeyingSet *)internal->link;
|
||||
|
||||
/* if we've run out of links in Scene list, jump over to the builtins list unless we're there already */
|
||||
|
||||
@@ -136,7 +136,7 @@ static void rna_SequenceEditor_sequences_all_begin(CollectionPropertyIterator *i
|
||||
|
||||
static void rna_SequenceEditor_sequences_all_next(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
Sequence *seq = (Sequence *)internal->link;
|
||||
|
||||
if (seq->seqbase.first)
|
||||
@@ -556,7 +556,7 @@ static char *rna_Sequence_path(PointerRNA *ptr)
|
||||
|
||||
static PointerRNA rna_SequenceEditor_meta_stack_get(CollectionPropertyIterator *iter)
|
||||
{
|
||||
ListBaseIterator *internal = iter->internal;
|
||||
ListBaseIterator *internal = &iter->internal.listbase;
|
||||
MetaStack *ms = (MetaStack *)internal->link;
|
||||
|
||||
return rna_pointer_inherit_refine(&iter->parent, &RNA_Sequence, ms->parseq);
|
||||
|
||||
Reference in New Issue
Block a user