skip rna property & function lookups for members starting with "_" (since makesrna disallows this)

added a way profile python startup in bpy/__init__.py, if'd out by default.
This commit is contained in:
2009-11-14 23:11:46 +00:00
parent 33da66d7b3
commit d04f94d0c6
2 changed files with 33 additions and 17 deletions

View File

@@ -64,4 +64,14 @@ def load_scripts(reload_scripts=False):
print("Reloading:", mod) print("Reloading:", mod)
reload(mod) reload(mod)
load_scripts()
if "-d" in sys.argv and False: # Enable this to measure startup speed
import cProfile
cProfile.run('import bpy; bpy.load_scripts()', 'blender.prof')
import pstats
p = pstats.Stats('blender.prof')
p.sort_stats('cumulative').print_stats(100)
else:
load_scripts()

View File

@@ -1379,7 +1379,10 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA * self, PyObject *pyname )
PropertyRNA *prop; PropertyRNA *prop;
FunctionRNA *func; FunctionRNA *func;
if ((prop = RNA_struct_find_property(&self->ptr, name))) { if(name[0]=='_') { // rna can't start with a "_", so for __dict__ and similar we can skip using rna lookups
ret = PyObject_GenericGetAttr((PyObject *)self, pyname);
}
else if ((prop = RNA_struct_find_property(&self->ptr, name))) {
ret = pyrna_prop_to_py(&self->ptr, prop); ret = pyrna_prop_to_py(&self->ptr, prop);
} }
else if ((func = RNA_struct_find_function(&self->ptr, name))) { else if ((func = RNA_struct_find_function(&self->ptr, name))) {
@@ -1485,24 +1488,27 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje
static PyObject *pyrna_prop_getattro( BPy_PropertyRNA *self, PyObject *pyname ) static PyObject *pyrna_prop_getattro( BPy_PropertyRNA *self, PyObject *pyname )
{ {
char *name = _PyUnicode_AsString(pyname); char *name = _PyUnicode_AsString(pyname);
PyObject *ret;
PropertyRNA *prop;
FunctionRNA *func;
if (RNA_property_type(self->prop) == PROP_COLLECTION) { if(name[0] != '_') {
PointerRNA r_ptr; if (RNA_property_type(self->prop) == PROP_COLLECTION) {
if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { PyObject *ret;
if ((prop = RNA_struct_find_property(&r_ptr, name))) { PropertyRNA *prop;
ret = pyrna_prop_to_py(&r_ptr, prop); FunctionRNA *func;
return ret; PointerRNA r_ptr;
} if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
else if ((func = RNA_struct_find_function(&r_ptr, name))) { if ((prop = RNA_struct_find_property(&r_ptr, name))) {
PyObject *self_collection= pyrna_struct_CreatePyObject(&r_ptr); ret = pyrna_prop_to_py(&r_ptr, prop);
ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self_collection, func);
Py_DECREF(self_collection);
return ret; return ret;
}
else if ((func = RNA_struct_find_function(&r_ptr, name))) {
PyObject *self_collection= pyrna_struct_CreatePyObject(&r_ptr);
ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self_collection, func);
Py_DECREF(self_collection);
return ret;
}
} }
} }
} }