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>2011-01-16 14:26:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-01-16 14:26:01 +0300
commit5b3bf80dd89ab08abf0f22a7eba636e7127955e2 (patch)
tree265550be1b663379e429cf8640e718884e0f1066 /source/blender/python
parentba96f02d4aa2da539157529af8039c0ebc65e686 (diff)
detect mathutils types with mathutils_array_parse(), was using PySequence_Fast(), converting into a tuple every time then back to a float array.
gives approx 6x speedup with eg mathutils.Vector(some_vector).
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/mathutils.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c
index f0eca793028..dc7c1811b80 100644
--- a/source/blender/python/generic/mathutils.c
+++ b/source/blender/python/generic/mathutils.c
@@ -81,8 +81,7 @@
static char M_Mathutils_doc[] =
"This module provides access to matrices, eulers, quaternions and vectors.";
-/* helper functionm returns length of the 'value', -1 on error */
-int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
+static int mathutils_array_parse_fast(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
{
PyObject *value_fast= NULL;
@@ -117,6 +116,37 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
return size;
}
+/* helper functionm returns length of the 'value', -1 on error */
+int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
+{
+#if 1 /* approx 6x speedup for mathutils types */
+ int size;
+
+ if( (VectorObject_Check(value) && (size= ((VectorObject *)value)->size)) ||
+ (EulerObject_Check(value) && (size= 3)) ||
+ (QuaternionObject_Check(value) && (size= 4)) ||
+ (ColorObject_Check(value) && (size= 3))
+ ) {
+ if(!BaseMath_ReadCallback((BaseMathObject *)value)) {
+ return -1;
+ }
+
+ if(size > array_max || size < array_min) {
+ if (array_max == array_min) PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected %d", error_prefix, size, array_max);
+ else PyErr_Format(PyExc_ValueError, "%.200s: sequence size is %d, expected [%d - %d]", error_prefix, size, array_min, array_max);
+ return -1;
+ }
+
+ memcpy(array, ((BaseMathObject *)value)->data, size * sizeof(float));
+ return size;
+ }
+ else
+#endif
+ {
+ return mathutils_array_parse_fast(array, array_min, array_max, value, error_prefix);
+ }
+}
+
//----------------------------------MATRIX FUNCTIONS--------------------