diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-09 09:32:15 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-09 09:32:15 +0400 |
commit | cecbb3498b245fbf2226c967001c4ab40b1c7b87 (patch) | |
tree | 143614f791f0a00afa6c78bee511e294d3c08c95 /source/blender/makesrna/intern/rna_define.c | |
parent | 02f6645bef3ebb3b802d03f6949f44d488e141bc (diff) |
add RNA_def_struct_ptr(...) to use for runtime struct registration, saves over 2000 string lookups on startup and gives overall ~10% speedup for starting blender on my system.
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 0a8254cb9c1..b94d7eb691f 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -623,13 +623,12 @@ static StructDefRNA *rna_find_def_struct(StructRNA *srna) } /* Struct Definition */ - -StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from) +StructRNA *RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom) { - StructRNA *srna, *srnafrom = NULL; + StructRNA *srna; StructDefRNA *ds = NULL, *dsfrom = NULL; PropertyRNA *prop; - + if (DefRNA.preprocess) { char error[512]; @@ -638,18 +637,6 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char * DefRNA.error = 1; } } - - if (from) { - /* find struct to derive from */ - for (srnafrom = brna->structs.first; srnafrom; srnafrom = srnafrom->cont.next) - if (strcmp(srnafrom->identifier, from) == 0) - break; - - if (!srnafrom) { - fprintf(stderr, "%s: struct %s not found to define %s.\n", __func__, from, identifier); - DefRNA.error = 1; - } - } srna = MEM_callocN(sizeof(StructRNA), "StructRNA"); DefRNA.laststruct = srna; @@ -670,7 +657,7 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char * else srna->base = srnafrom; } - + srna->identifier = identifier; srna->name = identifier; /* may be overwritten later RNA_def_struct_ui_text */ srna->description = ""; @@ -741,6 +728,28 @@ StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char * return srna; } +StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from) +{ + StructRNA *srnafrom = NULL; + + /* only use RNA_def_struct() while pre-processing, otherwise use RNA_def_struct_ptr() */ + BLI_assert(DefRNA.preprocess); + + if (from) { + /* find struct to derive from */ + for (srnafrom = brna->structs.first; srnafrom; srnafrom = srnafrom->cont.next) + if (strcmp(srnafrom->identifier, from) == 0) + break; + + if (!srnafrom) { + fprintf(stderr, "%s: struct %s not found to define %s.\n", __func__, from, identifier); + DefRNA.error = 1; + } + } + + return RNA_def_struct_ptr(brna, identifier, srnafrom); +} + void RNA_def_struct_sdna(StructRNA *srna, const char *structname) { StructDefRNA *ds; |