From b240b8e23115fe99f47ee5b3fd66fd3796ff8a1b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 4 Jan 2015 21:20:45 +1100 Subject: Freestyle: reserve array sizes before filling also use PyList_GET_ITEM when list size is known. --- source/blender/freestyle/intern/python/BPy_Operators.cpp | 3 ++- source/blender/freestyle/intern/python/BPy_ViewShape.cpp | 10 +++++++--- source/blender/freestyle/intern/python/Director.cpp | 6 ++++-- source/gameengine/Expressions/ListValue.cpp | 2 +- source/gameengine/Expressions/Value.cpp | 2 +- source/gameengine/Ketsji/KX_MouseActuator.cpp | 12 ++++++------ 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/source/blender/freestyle/intern/python/BPy_Operators.cpp b/source/blender/freestyle/intern/python/BPy_Operators.cpp index d3cb44f5903..57ec15f4150 100644 --- a/source/blender/freestyle/intern/python/BPy_Operators.cpp +++ b/source/blender/freestyle/intern/python/BPy_Operators.cpp @@ -532,8 +532,9 @@ static PyObject *Operators_create(BPy_Operators *self, PyObject *args, PyObject return NULL; } vector shaders; + shaders.reserve(PyList_Size(obj2)); for (int i = 0; i < PyList_Size(obj2); i++) { - PyObject *py_ss = PyList_GetItem(obj2, i); + PyObject *py_ss = PyList_GET_ITEM(obj2, i); if (!BPy_StrokeShader_Check(py_ss)) { PyErr_SetString(PyExc_TypeError, "Operators.create(): 2nd argument must be a list of StrokeShader objects"); return NULL; diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index 10073204842..6c6e821a1e4 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -228,8 +228,10 @@ static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void *UN PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects"); return -1; } - for (int i = 0; i < PyList_Size(list); i++) { - item = PyList_GetItem(list, i); + + v.reserve(PyList_Size(list)); + for (unsigned int i = 0; i < PyList_Size(list); i++) { + item = PyList_GET_ITEM(list, i); if (BPy_ViewVertex_Check(item)) { v.push_back(((BPy_ViewVertex *)item)->vv); } @@ -270,8 +272,10 @@ static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void *UNUSE PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects"); return -1; } + + v.reserve(PyList_Size(list)); for (int i = 0; i < PyList_Size(list); i++) { - item = PyList_GetItem(list, i); + item = PyList_GET_ITEM(list, i); if (BPy_ViewEdge_Check(item)) { v.push_back(((BPy_ViewEdge *)item)->ve); } diff --git a/source/blender/freestyle/intern/python/Director.cpp b/source/blender/freestyle/intern/python/Director.cpp index 653fd0b1d29..9f85e84e297 100644 --- a/source/blender/freestyle/intern/python/Director.cpp +++ b/source/blender/freestyle/intern/python/Director.cpp @@ -265,8 +265,9 @@ int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0D } else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) { vector vec; + vec.reserve(PyList_Size(result)); for (int i = 0; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GetItem(result, i))->vs; + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; vec.push_back(b); } ((UnaryFunction0D< vector > *)uf0D)->result = vec; @@ -318,8 +319,9 @@ int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D } else if (BPy_UnaryFunction1DVectorViewShape_Check(obj)) { vector vec; + vec.reserve(PyList_Size(result)); for (int i = 1; i < PyList_Size(result); i++) { - ViewShape *b = ((BPy_ViewShape *)PyList_GetItem(result, i))->vs; + ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs; vec.push_back(b); } ((UnaryFunction1D< vector > *)uf1D)->result = vec; diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp index 75e3b490505..5e0eb92eb58 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/ListValue.cpp @@ -432,7 +432,7 @@ static PyObject *listvalue_buffer_concat(PyObject *self, PyObject *other) for (i=0;iConvertPythonToValue(PyList_GetItem(other,i), true, "cList + pyList: CListValue, "); + listitemval = listval->ConvertPythonToValue(PyList_GET_ITEM(other, i), true, "cList + pyList: CListValue, "); if (listitemval) { listval_new->SetValue(i+numitems_orig, listitemval); diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp index bdef2dbd5b0..286db016476 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/Value.cpp @@ -568,7 +568,7 @@ CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_excepti Py_ssize_t numitems = PyList_GET_SIZE(pyobj); for (i=0;i