diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-02-15 03:31:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-02-15 05:46:47 +0300 |
commit | 4feb77cf03840dca4cc0b5e4b1a1256cd3b07c84 (patch) | |
tree | 4e303285ec3a89b8c115b044ee86da636881bd80 /source/blender/python/mathutils/mathutils_Vector.c | |
parent | 24f9ed0b348f3dc577975d83c59f9a325840a2fe (diff) |
mathutils: avoid extra alloc for Vector.lerp
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Vector.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_Vector.c | 23 |
1 files changed, 4 insertions, 19 deletions
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, |