[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34350] trunk/blender/source/blender/ python/generic/mathutils.c: detect mathutils types with mathutils_array_parse(), was using PySequence_Fast(), converting into a tuple every time then back to a float array.
Campbell Barton
ideasman42 at gmail.com
Sun Jan 16 12:26:02 CET 2011
Revision: 34350
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34350
Author: campbellbarton
Date: 2011-01-16 11:26:01 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
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).
Modified Paths:
--------------
trunk/blender/source/blender/python/generic/mathutils.c
Modified: trunk/blender/source/blender/python/generic/mathutils.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils.c 2011-01-16 10:36:27 UTC (rev 34349)
+++ trunk/blender/source/blender/python/generic/mathutils.c 2011-01-16 11:26:01 UTC (rev 34350)
@@ -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 @@
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--------------------
More information about the Bf-blender-cvs
mailing list