[Bf-blender-cvs] [4feb77c] master: mathutils: avoid extra alloc for Vector.lerp

Campbell Barton noreply at git.blender.org
Sun Feb 15 04:06:09 CET 2015


Commit: 4feb77cf03840dca4cc0b5e4b1a1256cd3b07c84
Author: Campbell Barton
Date:   Sun Feb 15 11:31:39 2015 +1100
Branches: master
https://developer.blender.org/rB4feb77cf03840dca4cc0b5e4b1a1256cd3b07c84

mathutils: avoid extra alloc for Vector.lerp

===================================================================

M	source/blender/python/mathutils/mathutils_Vector.c

===================================================================

diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 091412b..ef6b2c9 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -1167,9 +1167,8 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
 {
 	const int size = self->size;
 	PyObject *value = NULL;
-	float fac, ifac;
-	float *tvec, *vec;
-	int x;
+	float fac;
+	float *tvec;
 
 	if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac))
 		return NULL;
@@ -1182,23 +1181,9 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
 		return NULL;
 	}
 
-	vec = PyMem_Malloc(size * sizeof(float));
-	if (vec == NULL) {
-		PyErr_SetString(PyExc_MemoryError,
-		                "Vector.lerp(): "
-		                "problem allocating pointer space");
-		return NULL;
-	}
-
-	ifac = 1.0f - fac;
-
-	for (x = 0; x < size; x++) {
-		vec[x] = (ifac * self->vec[x]) + (fac * tvec[x]);
-	}
-
-	PyMem_Free(tvec);
+	interp_vn_vn(tvec, self->vec, 1.0f - fac, size);
 
-	return Vector_CreatePyObject_alloc(vec, size, Py_TYPE(self));
+	return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self));
 }
 
 PyDoc_STRVAR(Vector_slerp_doc,




More information about the Bf-blender-cvs mailing list