diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-16 13:36:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-16 13:36:27 +0300 |
commit | ba96f02d4aa2da539157529af8039c0ebc65e686 (patch) | |
tree | 10b4c8bd956d0a9bbd7c91f51c6f0e6b10e67d6c /source/blender/python | |
parent | 4dd92a988a5fe5a73ddeefbd663fe0e38b1808ab (diff) |
use fast sequence functions for python's bpy.props.EnumProperty() arg parsing.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 4fbcca3fe94..38d3c9161db 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -539,7 +539,7 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw Py_RETURN_NONE; } -static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int *defvalue, const short is_enum_flag) +static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, int *defvalue, const short is_enum_flag) { EnumPropertyItem *items= NULL; PyObject *item; @@ -547,12 +547,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int short def_used= 0; const char *def_cmp= NULL; - if(!PySequence_Check(value)) { - PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items"); - return NULL; - } - - seq_len= PySequence_Size(value); + seq_len= PySequence_Fast_GET_SIZE(seq_fast); if(is_enum_flag) { if(seq_len > RNA_ENUM_BITFLAG_SIZE) { @@ -580,17 +575,15 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int for(i=0; i<seq_len; i++) { EnumPropertyItem tmp= {0, "", 0, "", ""}; - item= PySequence_GetItem(value, i); - if(item==NULL || PyTuple_Check(item)==0) { + item= PySequence_Fast_GET_ITEM(seq_fast, i); + if(PyTuple_Check(item)==0) { PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected a sequence of tuples for the enum items"); if(items) MEM_freeN(items); - Py_XDECREF(item); return NULL; } if(!PyArg_ParseTuple(item, "sss", &tmp.identifier, &tmp.name, &tmp.description)) { PyErr_SetString(PyExc_TypeError, "EnumProperty(...): expected an identifier, name and description in the tuple"); - Py_DECREF(item); return NULL; } @@ -612,8 +605,6 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int } RNA_enum_item_add(&items, &totitem, &tmp); - - Py_DECREF(item); } RNA_enum_item_end(&items, &totitem); @@ -635,6 +626,7 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, PyObject *def, int return NULL; } } + return items; } @@ -661,7 +653,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) PyObject *def= NULL; int id_len; int defvalue=0; - PyObject *items= Py_None; + PyObject *items, *items_fast; EnumPropertyItem *eitems; PropertyRNA *prop; PyObject *pyopts= NULL; @@ -672,7 +664,14 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) BPY_PROPDEF_CHECK(EnumProperty, property_flag_enum_items) - eitems= enum_items_from_py(items, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0); + if(!(items_fast= PySequence_Fast(items, "EnumProperty(...): expected a sequence of tuples for the enum items"))) { + return NULL; + } + + eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0); + + Py_DECREF(items_fast); + if(!eitems) return NULL; |