[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34349] trunk/blender/source/blender/ python/intern/bpy_props.c: use fast sequence functions for python's bpy. props.EnumProperty() arg parsing.

Campbell Barton ideasman42 at gmail.com
Sun Jan 16 11:36:28 CET 2011


Revision: 34349
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34349
Author:   campbellbarton
Date:     2011-01-16 10:36:27 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
use fast sequence functions for python's bpy.props.EnumProperty() arg parsing.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_props.c

Modified: trunk/blender/source/blender/python/intern/bpy_props.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_props.c	2011-01-16 10:08:20 UTC (rev 34348)
+++ trunk/blender/source/blender/python/intern/bpy_props.c	2011-01-16 10:36:27 UTC (rev 34349)
@@ -539,7 +539,7 @@
 	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,13 +547,8 @@
 	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_Fast_GET_SIZE(seq_fast);
 
-	seq_len= PySequence_Size(value);
-
 	if(is_enum_flag) {
 		if(seq_len > RNA_ENUM_BITFLAG_SIZE) {
 			PyErr_SetString(PyExc_TypeError, "EnumProperty(...): maximum " STRINGIFY(RNA_ENUM_BITFLAG_SIZE) " members for a ENUM_FLAG type property");
@@ -580,17 +575,15 @@
 	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 @@
 		}
 
 		RNA_enum_item_add(&items, &totitem, &tmp);
-
-		Py_DECREF(item);
 	}
 
 	RNA_enum_item_end(&items, &totitem);
@@ -635,6 +626,7 @@
 			return NULL;
 		}
 	}
+
 	return items;
 }
 
@@ -661,7 +653,7 @@
 		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 @@
 
 		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;
 




More information about the Bf-blender-cvs mailing list