use string/int/length lookup functions for bpy.types, gives 20-30% overall startup...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 22 Jan 2010 14:06:42 +0000 (14:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 22 Jan 2010 14:06:42 +0000 (14:06 +0000)
source/blender/makesrna/intern/rna_rna.c
source/blender/python/intern/bpy_rna.c

index e6c21d8fedeaa9b3af4d23e8f27fa5aa287c2663..a2a6e7c361c0725e6f8f341dc898456c7dedf364 100644 (file)
@@ -798,6 +798,42 @@ static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, Point
        rna_iterator_listbase_begin(iter, &((BlenderRNA*)ptr->data)->structs, NULL);
 }
 
+/* optional, for faster lookups */
+static int rna_BlenderRNA_structs_length(PointerRNA *ptr, int index)
+{
+       return BLI_countlist(&((BlenderRNA*)ptr->data)->structs);
+}
+static PointerRNA rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index)
+{
+       StructRNA *srna= BLI_findlink(&((BlenderRNA*)ptr->data)->structs, index);
+
+       if(srna) {
+               PointerRNA r_ptr;
+               RNA_pointer_create(NULL, &RNA_Struct, srna, &r_ptr);
+               return r_ptr;
+       }
+       else {
+               return PointerRNA_NULL;
+       }
+}
+static PointerRNA rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key)
+{
+       StructRNA *srna= ((BlenderRNA*)ptr->data)->structs.first;
+       for(; srna; srna=srna->cont.next)
+               if(key[0] == srna->identifier[0] && strcmp(key, srna->identifier)==0)
+                       break;
+
+       if(srna) {
+               PointerRNA r_ptr;
+               RNA_pointer_create(NULL, &RNA_Struct, srna, &r_ptr);
+               return r_ptr;
+       }
+       else {
+               return PointerRNA_NULL;
+       }
+}
+
+
 #else
 
 static void rna_def_struct(BlenderRNA *brna)
@@ -1238,7 +1274,14 @@ void RNA_def_rna(BlenderRNA *brna)
        prop= RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_struct_type(prop, "Struct");
-       RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0);
+       RNA_def_property_collection_funcs(prop, "rna_BlenderRNA_structs_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get",
+               /* included for speed, can be removed */
+#if 0
+                       0,0,0);
+#else
+                       "rna_BlenderRNA_structs_length", "rna_BlenderRNA_structs_lookup_int", "rna_BlenderRNA_structs_lookup_string");
+#endif
+
        RNA_def_property_ui_text(prop, "Structs", "");
 }
 
index 97a0dcae290209425748ea8c4792b695aaa15579..8784d8b723ba19d29f0a286dd2d524c64bb91fc3 100644 (file)
@@ -3472,8 +3472,13 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam
 {
        PointerRNA newptr;
        PyObject *ret;
+       char *name= _PyUnicode_AsString(pyname);
        
-       if (RNA_property_collection_lookup_string(&self->ptr, self->prop, _PyUnicode_AsString(pyname), &newptr)) {
+       if(strcmp(name, "register")==0) {
+               /* this is called so often, make an exception and save a full lookup on all types */
+               ret= PyObject_GenericGetAttr((PyObject *)self, pyname);
+       }
+       else if (RNA_property_collection_lookup_string(&self->ptr, self->prop, name, &newptr)) {
                ret= pyrna_struct_Subtype(&newptr);
                if (ret==NULL) {
                        PyErr_Format(PyExc_SystemError, "bpy.types.%.200s subtype could not be generated, this is a bug!", _PyUnicode_AsString(pyname));