[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33878] trunk/blender/source/blender/ python/generic: return typle for mathutils slice's.

Campbell Barton ideasman42 at gmail.com
Fri Dec 24 04:51:40 CET 2010


Revision: 33878
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33878
Author:   campbellbarton
Date:     2010-12-24 04:51:34 +0100 (Fri, 24 Dec 2010)

Log Message:
-----------
return typle for mathutils slice's.
The main advantage with this is that its close to twice as fast to do 'vertex.co[:]' then 'tuple(vertex.co)', this is common for writing a vertex array.
the correct python behavior in this case is to return a copy of the original type, however euler and quats don't support different sizes so we cant do so easily.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/mathutils_color.c
    trunk/blender/source/blender/python/generic/mathutils_euler.c
    trunk/blender/source/blender/python/generic/mathutils_matrix.c
    trunk/blender/source/blender/python/generic/mathutils_quat.c
    trunk/blender/source/blender/python/generic/mathutils_vector.c

Modified: trunk/blender/source/blender/python/generic/mathutils_color.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_color.c	2010-12-23 17:47:06 UTC (rev 33877)
+++ trunk/blender/source/blender/python/generic/mathutils_color.c	2010-12-24 03:51:34 UTC (rev 33878)
@@ -213,7 +213,7 @@
 //sequence slice (get)
 static PyObject *Color_slice(ColorObject * self, int begin, int end)
 {
-	PyObject *list = NULL;
+	PyObject *tuple;
 	int count;
 
 	if(!BaseMath_ReadCallback(self))
@@ -222,14 +222,14 @@
 	CLAMP(begin, 0, COLOR_SIZE);
 	if (end<0) end= (COLOR_SIZE + 1) + end;
 	CLAMP(end, 0, COLOR_SIZE);
-	begin = MIN2(begin,end);
+	begin= MIN2(begin, end);
 
-	list = PyList_New(end - begin);
+	tuple= PyTuple_New(end - begin);
 	for(count= begin; count < end; count++) {
-		PyList_SET_ITEM(list, count - begin, PyFloat_FromDouble(self->col[count]));
+		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->col[count]));
 	}
 
-	return list;
+	return tuple;
 }
 //----------------------------object[z:y]------------------------
 //sequence slice (set)

Modified: trunk/blender/source/blender/python/generic/mathutils_euler.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_euler.c	2010-12-23 17:47:06 UTC (rev 33877)
+++ trunk/blender/source/blender/python/generic/mathutils_euler.c	2010-12-24 03:51:34 UTC (rev 33878)
@@ -443,7 +443,7 @@
 //sequence slice (get)
 static PyObject *Euler_slice(EulerObject * self, int begin, int end)
 {
-	PyObject *list = NULL;
+	PyObject *tuple;
 	int count;
 
 	if(!BaseMath_ReadCallback(self))
@@ -452,14 +452,14 @@
 	CLAMP(begin, 0, EULER_SIZE);
 	if (end<0) end= (EULER_SIZE + 1) + end;
 	CLAMP(end, 0, EULER_SIZE);
-	begin = MIN2(begin,end);
+	begin= MIN2(begin, end);
 
-	list = PyList_New(end - begin);
+	tuple= PyTuple_New(end - begin);
 	for(count = begin; count < end; count++) {
-		PyList_SET_ITEM(list, count - begin, PyFloat_FromDouble(self->eul[count]));
+		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->eul[count]));
 	}
 
-	return list;
+	return tuple;
 }
 //----------------------------object[z:y]------------------------
 //sequence slice (set)

Modified: trunk/blender/source/blender/python/generic/mathutils_matrix.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_matrix.c	2010-12-23 17:47:06 UTC (rev 33877)
+++ trunk/blender/source/blender/python/generic/mathutils_matrix.c	2010-12-24 03:51:34 UTC (rev 33878)
@@ -1398,7 +1398,7 @@
 static PyObject *Matrix_slice(MatrixObject * self, int begin, int end)
 {
 
-	PyObject *list = NULL;
+	PyObject *tuple;
 	int count;
 	
 	if(!BaseMath_ReadCallback(self))
@@ -1406,16 +1406,16 @@
 
 	CLAMP(begin, 0, self->rowSize);
 	CLAMP(end, 0, self->rowSize);
-	begin = MIN2(begin,end);
+	begin= MIN2(begin,end);
 
-	list = PyList_New(end - begin);
-	for(count = begin; count < end; count++) {
-		PyList_SET_ITEM(list, count - begin,
+	tuple= PyTuple_New(end - begin);
+	for(count= begin; count < end; count++) {
+		PyTuple_SET_ITEM(tuple, count - begin,
 				newVectorObject_cb((PyObject *)self, self->colSize, mathutils_matrix_vector_cb_index, count));
 
 	}
 
-	return list;
+	return tuple;
 }
 /*----------------------------object[z:y]------------------------
   sequence slice (set)*/

Modified: trunk/blender/source/blender/python/generic/mathutils_quat.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_quat.c	2010-12-23 17:47:06 UTC (rev 33877)
+++ trunk/blender/source/blender/python/generic/mathutils_quat.c	2010-12-24 03:51:34 UTC (rev 33878)
@@ -480,7 +480,7 @@
 //sequence slice (get)
 static PyObject *Quaternion_slice(QuaternionObject * self, int begin, int end)
 {
-	PyObject *list = NULL;
+	PyObject *tuple;
 	int count;
 
 	if(!BaseMath_ReadCallback(self))
@@ -489,14 +489,14 @@
 	CLAMP(begin, 0, QUAT_SIZE);
 	if (end<0) end= (QUAT_SIZE + 1) + end;
 	CLAMP(end, 0, QUAT_SIZE);
-	begin = MIN2(begin,end);
+	begin= MIN2(begin, end);
 
-	list = PyList_New(end - begin);
-	for(count = begin; count < end; count++) {
-		PyList_SET_ITEM(list, count - begin, PyFloat_FromDouble(self->quat[count]));
+	tuple= PyTuple_New(end - begin);
+	for(count= begin; count < end; count++) {
+		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->quat[count]));
 	}
 
-	return list;
+	return tuple;
 }
 //----------------------------object[z:y]------------------------
 //sequence slice (set)

Modified: trunk/blender/source/blender/python/generic/mathutils_vector.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_vector.c	2010-12-23 17:47:06 UTC (rev 33877)
+++ trunk/blender/source/blender/python/generic/mathutils_vector.c	2010-12-24 03:51:34 UTC (rev 33878)
@@ -807,7 +807,7 @@
   sequence slice (get) */
 static PyObject *Vector_slice(VectorObject *self, int begin, int end)
 {
-	PyObject *list = NULL;
+	PyObject *tuple;
 	int count;
 
 	if(!BaseMath_ReadCallback(self))
@@ -816,14 +816,14 @@
 	CLAMP(begin, 0, self->size);
 	if (end<0) end= self->size+end+1;
 	CLAMP(end, 0, self->size);
-	begin = MIN2(begin,end);
+	begin= MIN2(begin, end);
 
-	list = PyList_New(end - begin);
+	tuple= PyTuple_New(end - begin);
 	for(count = begin; count < end; count++) {
-		PyList_SET_ITEM(list, count - begin, PyFloat_FromDouble(self->vec[count]));
+		PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(self->vec[count]));
 	}
 
-	return list;
+	return tuple;
 }
 /*----------------------------object[z:y]------------------------
   sequence slice (set) */





More information about the Bf-blender-cvs mailing list