Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-06-20 03:05:21 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-06-20 03:05:21 +0400
commitaa0aac706e4381624482978110a54b5959414d14 (patch)
tree6ddf414bdcc52d7da10e2d7e621113aec48520dc /source/blender/makesrna/intern
parent7349d775b0c80a112cc90888db80f481a36c4b92 (diff)
2.5
* Optimized RNA property lookups and path resolving, still can be much better, but now the 1000 IPO example on bf-taskforce25 runs at reasonable speed. * Also an optimization in the depsgraph when dealing with many objects, this was actually also a bottleneck here.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r--source/blender/makesrna/intern/makesrna.c8
-rw-r--r--source/blender/makesrna/intern/rna_access.c83
-rw-r--r--source/blender/makesrna/intern/rna_define.c12
-rw-r--r--source/blender/makesrna/intern/rna_internal.h1
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_rna.c47
6 files changed, 112 insertions, 41 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index c8273513711..75293d83346 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -1488,8 +1488,8 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
if(nest != NULL) {
len= strlen(nest);
- strnest= MEM_mallocN(sizeof(char)*(len+1), "rna_generate_property -> strnest");
- errnest= MEM_mallocN(sizeof(char)*(len+1), "rna_generate_property -> errnest");
+ strnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> strnest");
+ errnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> errnest");
strcpy(strnest, "_"); strcat(strnest, nest);
strcpy(errnest, "."); strcat(errnest, nest);
@@ -1713,6 +1713,8 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier);
else fprintf(f, "NULL,\n");
+ fprintf(f, "\tNULL,\n");
+
parm= func->cont.properties.first;
if(parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
else fprintf(f, "\t{NULL, ");
@@ -1744,6 +1746,8 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
if(srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA*)srna->cont.prev)->identifier);
else fprintf(f, "NULL,\n");
+ fprintf(f, "\tNULL,\n");
+
prop= srna->cont.properties.first;
if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
else fprintf(f, "\t{NULL, ");
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 8d0d87a72d3..ba893319ce9 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -32,6 +32,7 @@
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
+#include "BLI_ghash.h"
#include "BKE_context.h"
#include "BKE_idprop.h"
@@ -46,10 +47,35 @@
#include "rna_internal.h"
-/* Exit */
+/* Init/Exit */
+
+void RNA_init()
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
+ if(!srna->cont.prophash) {
+ srna->cont.prophash= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp);
+
+ for(prop=srna->cont.properties.first; prop; prop=prop->next)
+ if(!(prop->flag & PROP_BUILTIN))
+ BLI_ghash_insert(srna->cont.prophash, (void*)prop->identifier, prop);
+ }
+ }
+}
void RNA_exit()
{
+ StructRNA *srna;
+
+ for(srna=BLENDER_RNA.structs.first; srna; srna=srna->cont.next) {
+ if(srna->cont.prophash) {
+ BLI_ghash_free(srna->cont.prophash, NULL, NULL);
+ srna->cont.prophash= NULL;
+ }
+ }
+
RNA_free(&BLENDER_RNA);
}
@@ -388,24 +414,13 @@ int RNA_struct_is_a(StructRNA *type, StructRNA *srna)
PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
{
- CollectionPropertyIterator iter;
- PropertyRNA *iterprop, *prop;
- int i = 0;
-
- iterprop= RNA_struct_iterator_property(ptr->type);
- RNA_property_collection_begin(ptr, iterprop, &iter);
- prop= NULL;
-
- for(; iter.valid; RNA_property_collection_next(&iter), i++) {
- if(strcmp(identifier, RNA_property_identifier(iter.ptr.data)) == 0) {
- prop= iter.ptr.data;
- break;
- }
- }
-
- RNA_property_collection_end(&iter);
+ PropertyRNA *iterprop= RNA_struct_iterator_property(ptr->type);
+ PointerRNA propptr;
- return prop;
+ if(RNA_property_collection_lookup_string(ptr, iterprop, identifier, &propptr))
+ return propptr.data;
+
+ return NULL;
}
/* Find the property which uses the given nested struct */
@@ -1643,12 +1658,18 @@ static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int
buf= MEM_callocN(sizeof(char)*(len+1), "rna_path_token");
/* copy string, taking into account escaped ] */
- for(p=*path, i=0, j=0; i<len; i++, p++) {
- if(*p == '\\' && *(p+1) == ']');
- else buf[j++]= *p;
- }
+ if(bracket) {
+ for(p=*path, i=0, j=0; i<len; i++, p++) {
+ if(*p == '\\' && *(p+1) == ']');
+ else buf[j++]= *p;
+ }
- buf[j]= 0;
+ buf[j]= 0;
+ }
+ else {
+ memcpy(buf, *path, sizeof(char)*len);
+ buf[len]= '\0';
+ }
/* set path to start of next token */
if(*p == ']') p++;
@@ -1660,8 +1681,7 @@ static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int
int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
{
- CollectionPropertyIterator iter;
- PropertyRNA *prop, *iterprop;
+ PropertyRNA *prop;
PointerRNA curptr, nextptr;
char fixedbuf[256], *token;
int len, intkey;
@@ -1676,18 +1696,7 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope
if(!token)
return 0;
- iterprop= RNA_struct_iterator_property(curptr.type);
- RNA_property_collection_begin(&curptr, iterprop, &iter);
- prop= NULL;
-
- for(; iter.valid; RNA_property_collection_next(&iter)) {
- if(strcmp(token, RNA_property_identifier(iter.ptr.data)) == 0) {
- prop= iter.ptr.data;
- break;
- }
- }
-
- RNA_property_collection_end(&iter);
+ prop= RNA_struct_find_property(&curptr, token);
if(token != fixedbuf)
MEM_freeN(token);
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index d91f538d412..51c1818eed9 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -38,6 +38,8 @@
#include "RNA_define.h"
#include "RNA_types.h"
+#include "BLI_ghash.h"
+
#include "rna_internal.h"
/* Global used during defining */
@@ -557,6 +559,7 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
/* copy from struct to derive stuff, a bit clumsy since we can't
* use MEM_dupallocN, data structs may not be alloced but builtin */
memcpy(srna, srnafrom, sizeof(StructRNA));
+ srna->cont.prophash= NULL;
srna->cont.properties.first= srna->cont.properties.last= NULL;
srna->functions.first= srna->functions.last= NULL;
srna->py_type= NULL;
@@ -604,7 +607,7 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *
if(DefRNA.preprocess) {
RNA_def_property_struct_type(prop, "Property");
- RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, 0, 0, 0);
+ RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, "rna_builtin_properties_lookup_string", 0, 0);
}
else {
#ifdef RNA_RUNTIME
@@ -923,8 +926,13 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier
break;
}
}
- else
+ else {
prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
+#ifdef RNA_RUNTIME
+ if(cont->prophash)
+ BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
+#endif
+ }
rna_addtail(&cont->properties, prop);
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 61cde5a01a3..362217e3123 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -217,6 +217,7 @@ void rna_builtin_properties_begin(struct CollectionPropertyIterator *iter, struc
void rna_builtin_properties_next(struct CollectionPropertyIterator *iter);
PointerRNA rna_builtin_properties_get(struct CollectionPropertyIterator *iter);
PointerRNA rna_builtin_type_get(struct PointerRNA *ptr);
+PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key);
/* Iterators */
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index d93e6f4d7cf..8bae21cca2b 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -37,6 +37,7 @@ struct ReportList;
struct CollectionPropertyIterator;
struct bContext;
struct IDProperty;
+struct GHash;
#define RNA_MAX_ARRAY 32
@@ -83,6 +84,7 @@ typedef PointerRNA (*PropCollectionLookupStringFunc)(struct PointerRNA *ptr, con
typedef struct ContainerRNA {
void *next, *prev;
+ struct GHash *prophash;
ListBase properties;
} ContainerRNA;
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index bd3a8ae5580..6fa275cec91 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -34,6 +34,8 @@
#ifdef RNA_RUNTIME
+#include "BLI_ghash.h"
+
/* Struct */
static void rna_Struct_identifier_get(PointerRNA *ptr, char *value)
@@ -277,6 +279,51 @@ PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter)
return rna_Struct_properties_get(iter);
}
+PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ IDProperty *group, *idp;
+ PointerRNA propptr;
+
+ memset(&propptr, 0, sizeof(propptr));
+ srna= ptr->type;
+
+ do {
+ if(srna->cont.prophash) {
+ prop= BLI_ghash_lookup(srna->cont.prophash, (void*)key);
+
+ if(prop) {
+ propptr.type= &RNA_Property;
+ propptr.data= prop;
+ return propptr;
+ }
+ }
+
+ for(prop=srna->cont.properties.first; prop; prop=prop->next) {
+ if(!(prop->flag & PROP_BUILTIN) && strcmp(prop->identifier, key)==0) {
+ propptr.type= &RNA_Property;
+ propptr.data= prop;
+ return propptr;
+ }
+ }
+ } while((srna=srna->base));
+
+ group= RNA_struct_idproperties(ptr, 0);
+
+ if(group) {
+ for(idp=group->data.group.first; idp; idp=idp->next) {
+ if(strcmp(idp->name, key) == 0) {
+ propptr.type= &RNA_Property;
+ propptr.data= idp;
+ return propptr;
+ }
+ }
+ }
+
+ return propptr;
+}
+
PointerRNA rna_builtin_type_get(PointerRNA *ptr)
{
return rna_pointer_inherit_refine(ptr, &RNA_Struct, ptr->type);