From 4feb77cf03840dca4cc0b5e4b1a1256cd3b07c84 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 15 Feb 2015 11:31:39 +1100 Subject: mathutils: avoid extra alloc for Vector.lerp --- source/blender/python/mathutils/mathutils_Vector.c | 23 ++++------------------ 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 091412b0f53..ef6b2c9759f 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, -- cgit v1.2.3