Freestyle: reserve array sizes before filling
also use PyList_GET_ITEM when list size is known.
This commit is contained in:
@@ -532,8 +532,9 @@ static PyObject *Operators_create(BPy_Operators *self, PyObject *args, PyObject
|
||||
return NULL;
|
||||
}
|
||||
vector<StrokeShader *> 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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -265,8 +265,9 @@ int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0D
|
||||
}
|
||||
else if (BPy_UnaryFunction0DVectorViewShape_Check(obj)) {
|
||||
vector<ViewShape*> 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<ViewShape*> > *)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<ViewShape*> 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<ViewShape*> > *)uf1D)->result = vec;
|
||||
|
||||
Reference in New Issue
Block a user