Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-07-29 02:58:10 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-07-29 03:49:35 +0300
commit339915a96269ffdd8f48335dda050f4aa071caed (patch)
treeb7723441798a3c0adabd9f1f8a8bd1c154c0f0df /source/blender/python/generic/idprop_py_api.c
parent96f08bf9a8e0cfcbbc774c3c00c58d405e3dc55c (diff)
Optimize PySequence_Fast usage
Access arrays directly, avoiding type-check every time.
Diffstat (limited to 'source/blender/python/generic/idprop_py_api.c')
-rw-r--r--source/blender/python/generic/idprop_py_api.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 30e0ccdb106..db8ed072722 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -299,12 +299,14 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
/* returns NULL on success, error string on failure */
static char idp_sequence_type(PyObject *seq_fast)
{
+ PyObject **seq_fast_items = PySequence_Fast_ITEMS(seq_fast);
PyObject *item;
char type = IDP_INT;
Py_ssize_t i, len = PySequence_Fast_GET_SIZE(seq_fast);
+
for (i = 0; i < len; i++) {
- item = PySequence_Fast_GET_ITEM(seq_fast, i);
+ item = seq_fast_items[i];
if (PyFloat_Check(item)) {
if (type == IDP_IDPARRAY) { /* mixed dict/int */
return -1;
@@ -396,14 +398,17 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group,
//prop->subtype = IDP_STRING_SUB_BYTE;
}
else if (PySequence_Check(ob)) {
- PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop");
+ PyObject *ob_seq_fast;
+ PyObject **ob_seq_fast_items;
PyObject *item;
int i;
- if (ob_seq_fast == NULL) {
+ if (!(ob_seq_fast = PySequence_Fast(ob, "py -> idprop"))) {
return false;
}
+ ob_seq_fast_items = PySequence_Fast_ITEMS(ob_seq_fast);
+
if ((val.array.type = idp_sequence_type(ob_seq_fast)) == (char)-1) {
Py_DECREF(ob_seq_fast);
PyErr_SetString(PyExc_TypeError, "only floats, ints and dicts are allowed in ID property arrays");
@@ -424,7 +429,7 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group,
prop = IDP_New(IDP_ARRAY, &val, name);
prop_data = IDP_Array(prop);
for (i = 0; i < val.array.len; i++) {
- item = PySequence_Fast_GET_ITEM(ob_seq_fast, i);
+ item = ob_seq_fast_items[i];
if (((prop_data[i] = PyFloat_AsDouble(item)) == -1.0) && PyErr_Occurred()) {
Py_DECREF(ob_seq_fast);
return false;
@@ -438,7 +443,7 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group,
prop = IDP_New(IDP_ARRAY, &val, name);
prop_data = IDP_Array(prop);
for (i = 0; i < val.array.len; i++) {
- item = PySequence_Fast_GET_ITEM(ob_seq_fast, i);
+ item = ob_seq_fast_items[i];
if (((prop_data[i] = _PyLong_AsInt(item)) == -1) && PyErr_Occurred()) {
Py_DECREF(ob_seq_fast);
return false;
@@ -450,7 +455,7 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group,
{
prop = IDP_NewIDPArray(name);
for (i = 0; i < val.array.len; i++) {
- item = PySequence_Fast_GET_ITEM(ob_seq_fast, i);
+ item = ob_seq_fast_items[i];
if (BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item) == false) {
Py_DECREF(ob_seq_fast);