Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-11-05 04:51:59 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-11-05 04:51:59 +0400
commit8c5597eb4964086c715b7d0038ddb4c6cb718296 (patch)
tree34d0a78421e01ee6ceb2b372c85023b55a302d06 /source/blender/freestyle/intern/python/BPy_Convert.cpp
parent737239c4c4f1b422c741d53b19bf21939d7382c3 (diff)
Additional code improvements: avoid unnecessary Python object allocations in Freestyle.
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_Convert.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.cpp193
1 files changed, 103 insertions, 90 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index bb907ec572c..56c096a1eae 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -512,103 +512,100 @@ Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj)
return static_cast<Nature::EdgeNature>(PyLong_AsLong(obj));
}
-Vec2f *Vec2f_ptr_from_PyObject(PyObject *obj)
-{
- Vec2f *v;
- if ((v = Vec2f_ptr_from_Vector(obj)))
- return v;
- if ((v = Vec2f_ptr_from_PyList(obj)))
- return v;
- if ((v = Vec2f_ptr_from_PyTuple(obj)))
- return v;
- return NULL;
+bool Vec2f_ptr_from_PyObject(PyObject *obj, Vec2f *vec)
+{
+ if (Vec2f_ptr_from_Vector(obj, vec))
+ return true;
+ if (Vec2f_ptr_from_PyList(obj, vec))
+ return true;
+ if (Vec2f_ptr_from_PyTuple(obj, vec))
+ return true;
+ return false;
}
-Vec3f *Vec3f_ptr_from_PyObject(PyObject *obj)
+bool Vec3f_ptr_from_PyObject(PyObject *obj, Vec3f *vec)
{
- Vec3f *v;
- if ((v = Vec3f_ptr_from_Vector(obj)))
- return v;
- if ((v = Vec3f_ptr_from_Color(obj)))
- return v;
- if ((v = Vec3f_ptr_from_PyList(obj)))
- return v;
- if ((v = Vec3f_ptr_from_PyTuple(obj)))
- return v;
- return NULL;
+ if (Vec3f_ptr_from_Vector(obj, vec))
+ return true;
+ if (Vec3f_ptr_from_Color(obj, vec))
+ return true;
+ if (Vec3f_ptr_from_PyList(obj, vec))
+ return true;
+ if (Vec3f_ptr_from_PyTuple(obj, vec))
+ return true;
+ return false;
}
-Vec3r *Vec3r_ptr_from_PyObject(PyObject *obj)
+bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r *vec)
{
- Vec3r *v;
- if ((v = Vec3r_ptr_from_Vector(obj)))
- return v;
- if ((v = Vec3r_ptr_from_Color(obj)))
- return v;
- if ((v = Vec3r_ptr_from_PyList(obj)))
- return v;
- if ((v = Vec3r_ptr_from_PyTuple(obj)))
- return v;
- return NULL;
+ if (Vec3r_ptr_from_Vector(obj, vec))
+ return true;
+ if (Vec3r_ptr_from_Color(obj, vec))
+ return true;
+ if (Vec3r_ptr_from_PyList(obj, vec))
+ return true;
+ if (Vec3r_ptr_from_PyTuple(obj, vec))
+ return true;
+ return false;
}
-Vec2f *Vec2f_ptr_from_Vector(PyObject *obj)
+bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f *vec)
{
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2)
- return NULL;
+ return false;
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
- return NULL;
- float x = ((VectorObject *)obj)->vec[0];
- float y = ((VectorObject *)obj)->vec[1];
- return new Vec2f(x, y);
+ return false;
+ vec[0] = ((VectorObject *)obj)->vec[0];
+ vec[1] = ((VectorObject *)obj)->vec[1];
+ return true;
}
-Vec3f *Vec3f_ptr_from_Vector(PyObject *obj)
+bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f *vec)
{
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
- return NULL;
+ return false;
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
- return NULL;
- float x = ((VectorObject *)obj)->vec[0];
- float y = ((VectorObject *)obj)->vec[1];
- float z = ((VectorObject *)obj)->vec[2];
- return new Vec3f(x, y, z);
+ return false;
+ vec[0] = ((VectorObject *)obj)->vec[0];
+ vec[1] = ((VectorObject *)obj)->vec[1];
+ vec[2] = ((VectorObject *)obj)->vec[2];
+ return true;
}
-Vec3r *Vec3r_ptr_from_Vector(PyObject *obj)
+bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r *vec)
{
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3)
- return NULL;
+ return false;
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
- return NULL;
- real x = ((VectorObject *)obj)->vec[0];
- real y = ((VectorObject *)obj)->vec[1];
- real z = ((VectorObject *)obj)->vec[2];
- return new Vec3r(x, y, z);
+ return false;
+ vec[0] = ((VectorObject *)obj)->vec[0];
+ vec[1] = ((VectorObject *)obj)->vec[1];
+ vec[2] = ((VectorObject *)obj)->vec[2];
+ return true;
}
-Vec3f *Vec3f_ptr_from_Color(PyObject *obj)
+bool Vec3f_ptr_from_Color(PyObject *obj, Vec3f *vec)
{
if (!ColorObject_Check(obj))
- return NULL;
+ return false;
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
- return NULL;
- float r = ((ColorObject *)obj)->col[0];
- float g = ((ColorObject *)obj)->col[1];
- float b = ((ColorObject *)obj)->col[2];
- return new Vec3f(r, g, b);
+ return false;
+ vec[0] = ((ColorObject *)obj)->col[0];
+ vec[1] = ((ColorObject *)obj)->col[1];
+ vec[2] = ((ColorObject *)obj)->col[2];
+ return true;
}
-Vec3r *Vec3r_ptr_from_Color(PyObject *obj)
+bool Vec3r_ptr_from_Color(PyObject *obj, Vec3r *vec)
{
if (!ColorObject_Check(obj))
- return NULL;
+ return false;
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1)
- return NULL;
- real r = ((ColorObject *)obj)->col[0];
- real g = ((ColorObject *)obj)->col[1];
- real b = ((ColorObject *)obj)->col[2];
- return new Vec3r(r, g, b);
+ return false;
+ vec[0] = ((ColorObject *)obj)->col[0];
+ vec[1] = ((ColorObject *)obj)->col[1];
+ vec[2] = ((ColorObject *)obj)->col[2];
+ return true;
}
static int float_array_from_PyList(PyObject *obj, float *v, int n)
@@ -623,37 +620,45 @@ static int float_array_from_PyList(PyObject *obj, float *v, int n)
return 1;
}
-Vec2f *Vec2f_ptr_from_PyList(PyObject *obj)
+bool Vec2f_ptr_from_PyList(PyObject *obj, Vec2f *vec)
{
float v[2];
if (!PyList_Check(obj) || PyList_Size(obj) != 2)
- return NULL;
+ return false;
if (!float_array_from_PyList(obj, v, 2))
- return NULL;
- return new Vec2f(v[0], v[1]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ return true;
}
-Vec3f *Vec3f_ptr_from_PyList(PyObject *obj)
+bool Vec3f_ptr_from_PyList(PyObject *obj, Vec3f *vec)
{
float v[3];
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
- return NULL;
+ return false;
if (!float_array_from_PyList(obj, v, 3))
- return NULL;
- return new Vec3f(v[0], v[1], v[2]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ vec[2] = v[2];
+ return true;
}
-Vec3r *Vec3r_ptr_from_PyList(PyObject *obj)
+bool Vec3r_ptr_from_PyList(PyObject *obj, Vec3r *vec)
{
float v[3];
if (!PyList_Check(obj) || PyList_Size(obj) != 3)
- return NULL;
+ return false;
if (!float_array_from_PyList(obj, v, 3))
- return NULL;
- return new Vec3r(v[0], v[1], v[2]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ vec[2] = v[2];
+ return true;
}
static int float_array_from_PyTuple(PyObject *obj, float *v, int n)
@@ -668,37 +673,45 @@ static int float_array_from_PyTuple(PyObject *obj, float *v, int n)
return 1;
}
-Vec2f *Vec2f_ptr_from_PyTuple(PyObject *obj)
+bool Vec2f_ptr_from_PyTuple(PyObject *obj, Vec2f *vec)
{
float v[2];
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 2)
- return NULL;
+ return false;
if (!float_array_from_PyTuple(obj, v, 2))
- return NULL;
- return new Vec2f(v[0], v[1]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ return true;
}
-Vec3f *Vec3f_ptr_from_PyTuple(PyObject *obj)
+bool Vec3f_ptr_from_PyTuple(PyObject *obj, Vec3f *vec)
{
float v[3];
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
- return NULL;
+ return false;
if (!float_array_from_PyTuple(obj, v, 3))
- return NULL;
- return new Vec3f(v[0], v[1], v[2]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ vec[2] = v[2];
+ return true;
}
-Vec3r *Vec3r_ptr_from_PyTuple(PyObject *obj)
+bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r *vec)
{
float v[3];
if (!PyTuple_Check(obj) || PyTuple_Size(obj) != 3)
- return NULL;
+ return false;
if (!float_array_from_PyTuple(obj, v, 3))
- return NULL;
- return new Vec3r(v[0], v[1], v[2]);
+ return false;
+ vec[0] = v[0];
+ vec[1] = v[1];
+ vec[2] = v[2];
+ return true;
}
// helper for argument parsing