diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-07-29 02:58:10 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-07-29 03:49:35 +0300 |
commit | 339915a96269ffdd8f48335dda050f4aa071caed (patch) | |
tree | b7723441798a3c0adabd9f1f8a8bd1c154c0f0df /source/blender/python/generic/py_capi_utils.c | |
parent | 96f08bf9a8e0cfcbbc774c3c00c58d405e3dc55c (diff) |
Optimize PySequence_Fast usage
Access arrays directly, avoiding type-check every time.
Diffstat (limited to 'source/blender/python/generic/py_capi_utils.c')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 17bd63bf5eb..d53e5629693 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -53,6 +53,7 @@ int PyC_AsArray_FAST( const PyTypeObject *type, const bool is_double, const char *error_prefix) { const Py_ssize_t value_len = PySequence_Fast_GET_SIZE(value_fast); + PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); Py_ssize_t i; BLI_assert(PyList_Check(value_fast) || PyTuple_Check(value_fast)); @@ -69,13 +70,13 @@ int PyC_AsArray_FAST( if (is_double) { double *array_double = array; for (i = 0; i < length; i++) { - array_double[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i)); + array_double[i] = PyFloat_AsDouble(value_fast_items[i]); } } else { float *array_float = array; for (i = 0; i < length; i++) { - array_float[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i)); + array_float[i] = PyFloat_AsDouble(value_fast_items[i]); } } } @@ -83,13 +84,13 @@ int PyC_AsArray_FAST( /* could use is_double for 'long int' but no use now */ int *array_int = array; for (i = 0; i < length; i++) { - array_int[i] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value_fast, i)); + array_int[i] = PyLong_AsLong(value_fast_items[i]); } } else if (type == &PyBool_Type) { int *array_bool = array; for (i = 0; i < length; i++) { - array_bool[i] = (PyLong_AsLong(PySequence_Fast_GET_ITEM(value_fast, i)) != 0); + array_bool[i] = (PyLong_AsLong(value_fast_items[i]) != 0); } } else { |