forked from bartvdbraak/blender
py api
- use Py_ssize_t when dealing with python sequence sizes - dont call PySequence_Size(py_b) in a loop (its slow). - use faster sequence/float parsing in aud.Factory.filter
This commit is contained in:
parent
d98bcb8a77
commit
928e2784c6
@ -848,6 +848,8 @@ Factory_filter(Factory* self, PyObject* args)
|
|||||||
{
|
{
|
||||||
PyObject* py_b;
|
PyObject* py_b;
|
||||||
PyObject* py_a = NULL;
|
PyObject* py_a = NULL;
|
||||||
|
Py_ssize_t py_a_len;
|
||||||
|
Py_ssize_t py_b_len;
|
||||||
|
|
||||||
if(!PyArg_ParseTuple(args, "O|O:filter", &py_b, &py_a))
|
if(!PyArg_ParseTuple(args, "O|O:filter", &py_b, &py_a))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -858,7 +860,10 @@ Factory_filter(Factory* self, PyObject* args)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!PySequence_Size(py_b) || (py_a != NULL && !PySequence_Size(py_a)))
|
py_a_len= py_a ? PySequence_Size(py_a) : 0;
|
||||||
|
py_b_len= PySequence_Size(py_b);
|
||||||
|
|
||||||
|
if(!py_b_len || ((py_a != NULL) && !py_b_len))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_ValueError, "The sequence has to contain at least one value!");
|
PyErr_SetString(PyExc_ValueError, "The sequence has to contain at least one value!");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -867,30 +872,31 @@ Factory_filter(Factory* self, PyObject* args)
|
|||||||
std::vector<float> a, b;
|
std::vector<float> a, b;
|
||||||
PyObject* py_value;
|
PyObject* py_value;
|
||||||
float value;
|
float value;
|
||||||
int result;
|
|
||||||
|
|
||||||
for(int i = 0; i < PySequence_Size(py_b); i++)
|
for(Py_ssize_t i = 0; i < py_b_len; i++)
|
||||||
{
|
{
|
||||||
py_value = PySequence_GetItem(py_b, i);
|
py_value = PySequence_GetItem(py_b, i);
|
||||||
result = PyArg_Parse(py_value, "f:filter", &value);
|
value= (float)PyFloat_AsDouble(py_value);
|
||||||
Py_DECREF(py_value);
|
Py_DECREF(py_value);
|
||||||
|
|
||||||
if(!result)
|
if (value==-1.0f && PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
b.push_back(value);
|
b.push_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(py_a)
|
if(py_a)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < PySequence_Size(py_a); i++)
|
for(Py_ssize_t i = 0; i < py_a_len; i++)
|
||||||
{
|
{
|
||||||
py_value = PySequence_GetItem(py_a, i);
|
py_value = PySequence_GetItem(py_a, i);
|
||||||
result = PyArg_Parse(py_value, "f:filter", &value);
|
value= (float)PyFloat_AsDouble(py_value);
|
||||||
Py_DECREF(py_value);
|
Py_DECREF(py_value);
|
||||||
|
|
||||||
if(!result)
|
if (value==-1.0f && PyErr_Occurred()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
a.push_back(value);
|
a.push_back(value);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ static int idp_sequence_type(PyObject *seq)
|
|||||||
PyObject *item;
|
PyObject *item;
|
||||||
int type= IDP_INT;
|
int type= IDP_INT;
|
||||||
|
|
||||||
int i, len = PySequence_Size(seq);
|
Py_ssize_t i, len = PySequence_Size(seq);
|
||||||
for (i=0; i < len; i++) {
|
for (i=0; i < len; i++) {
|
||||||
item = PySequence_GetItem(seq, i);
|
item = PySequence_GetItem(seq, i);
|
||||||
if (PyFloat_Check(item)) {
|
if (PyFloat_Check(item)) {
|
||||||
|
@ -286,8 +286,8 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
|||||||
Buffer *buffer;
|
Buffer *buffer;
|
||||||
int dimensions[MAX_DIMENSIONS];
|
int dimensions[MAX_DIMENSIONS];
|
||||||
|
|
||||||
int i, type;
|
int type;
|
||||||
int ndimensions = 0;
|
Py_ssize_t i, ndimensions = 0;
|
||||||
|
|
||||||
if(kwds && PyDict_Size(kwds)) {
|
if(kwds && PyDict_Size(kwds)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -1718,7 +1718,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
|
|||||||
}
|
}
|
||||||
case PROP_COLLECTION:
|
case PROP_COLLECTION:
|
||||||
{
|
{
|
||||||
int seq_len, i;
|
Py_ssize_t seq_len, i;
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
PointerRNA itemptr;
|
PointerRNA itemptr;
|
||||||
ListBase *lb;
|
ListBase *lb;
|
||||||
@ -1736,7 +1736,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
|
|||||||
}
|
}
|
||||||
|
|
||||||
seq_len= PySequence_Size(value);
|
seq_len= PySequence_Size(value);
|
||||||
for(i=0; i<seq_len; i++) {
|
for(i=0; i < seq_len; i++) {
|
||||||
item= PySequence_GetItem(value, i);
|
item= PySequence_GetItem(value, i);
|
||||||
|
|
||||||
if(item==NULL) {
|
if(item==NULL) {
|
||||||
|
@ -61,12 +61,12 @@ typedef void (*RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *)
|
|||||||
static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[],
|
static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[],
|
||||||
ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
|
ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
|
||||||
{
|
{
|
||||||
int i;
|
Py_ssize_t i;
|
||||||
|
|
||||||
/* not the last dimension */
|
/* not the last dimension */
|
||||||
if (dim + 1 < totdim) {
|
if (dim + 1 < totdim) {
|
||||||
/* check that a sequence contains dimsize[dim] items */
|
/* check that a sequence contains dimsize[dim] items */
|
||||||
const int seq_size= PySequence_Size(seq);
|
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||||
if(seq_size == -1) {
|
if(seq_size == -1) {
|
||||||
PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'",
|
PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'",
|
||||||
error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name);
|
error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name);
|
||||||
@ -147,8 +147,8 @@ static int count_items(PyObject *seq, int dim)
|
|||||||
int totitem= 0;
|
int totitem= 0;
|
||||||
|
|
||||||
if(dim > 1) {
|
if(dim > 1) {
|
||||||
const int seq_size= PySequence_Size(seq);
|
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||||
int i;
|
Py_ssize_t i;
|
||||||
for (i= 0; i < seq_size; i++) {
|
for (i= 0; i < seq_size; i++) {
|
||||||
PyObject *item= PySequence_GetItem(seq, i);
|
PyObject *item= PySequence_GetItem(seq, i);
|
||||||
if(item) {
|
if(item) {
|
||||||
@ -281,9 +281,9 @@ static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *pro
|
|||||||
|
|
||||||
static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index)
|
static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, unsigned int item_size, int *index, ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
|
||||||
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||||
const int seq_size= PySequence_Size(seq);
|
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||||
|
Py_ssize_t i;
|
||||||
|
|
||||||
/* Regarding PySequence_GetItem() failing.
|
/* Regarding PySequence_GetItem() failing.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user