mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 18:03:07 +03:00
Use PySequence_Fast* to iterate over the list
Pre commit: $ NOSE_PROCESSES=0 PILLOW_RUN_KNOWN_BAD=1 time ./test-installed.py Tests/test_image_point.py .. ---------------------------------------------------------------------- Ran 2 tests in 132.056s OK 131.63user 0.62system 2:12.28elapsed 99%CPU (0avgtext+0avgdata 292176maxresident)k 264inputs+0outputs (2major+451088minor)pagefaults 0swaps Post: $ NOSE_PROCESSES=0 PILLOW_RUN_KNOWN_BAD=1 time ./test-installed.py Tests/test_image_point.py .. ---------------------------------------------------------------------- Ran 2 tests in 0.338s OK 0.52user 0.06system 0:00.59elapsed 98%CPU (0avgtext+0avgdata 257584maxresident)k 176inputs+32outputs (2major+18033minor)pagefaults 0swaps $ python --version Python 2.7.6 (2.3.1+dfsg-1~ppa1, Jun 20 2014, 09:27:47) [PyPy 2.3.1 with GCC 4.6.3]
This commit is contained in:
parent
94ca2b1076
commit
a5aea42bc9
86
_imaging.c
86
_imaging.c
|
@ -365,9 +365,12 @@ getbands(const char* mode)
|
||||||
static void*
|
static void*
|
||||||
getlist(PyObject* arg, int* length, const char* wrong_length, int type)
|
getlist(PyObject* arg, int* length, const char* wrong_length, int type)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n, itemp;
|
||||||
|
double dtemp;
|
||||||
void* list;
|
void* list;
|
||||||
|
PyObject* seq;
|
||||||
|
PyObject* op;
|
||||||
|
|
||||||
if (!PySequence_Check(arg)) {
|
if (!PySequence_Check(arg)) {
|
||||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -383,70 +386,41 @@ getlist(PyObject* arg, int* length, const char* wrong_length, int type)
|
||||||
if (!list)
|
if (!list)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
|
||||||
|
seq = PySequence_Fast(arg, must_be_sequence);
|
||||||
|
if (!seq) {
|
||||||
|
free(list);
|
||||||
|
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TYPE_UINT8:
|
case TYPE_UINT8:
|
||||||
if (PyList_Check(arg)) {
|
for (i = 0; i < n; i++) {
|
||||||
for (i = 0; i < n; i++) {
|
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
itemp = PyInt_AsLong(op);
|
||||||
int temp = PyInt_AsLong(op);
|
((UINT8*)list)[i] = CLIP(itemp);
|
||||||
((UINT8*)list)[i] = CLIP(temp);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
PyObject *op = PySequence_GetItem(arg, i);
|
|
||||||
int temp = PyInt_AsLong(op);
|
|
||||||
Py_XDECREF(op);
|
|
||||||
((UINT8*)list)[i] = CLIP(temp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TYPE_INT32:
|
case TYPE_INT32:
|
||||||
if (PyList_Check(arg)) {
|
for (i = 0; i < n; i++) {
|
||||||
for (i = 0; i < n; i++) {
|
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
itemp = PyInt_AsLong(op);
|
||||||
int temp = PyInt_AsLong(op);
|
((INT32*)list)[i] = itemp;
|
||||||
((INT32*)list)[i] = temp;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
PyObject *op = PySequence_GetItem(arg, i);
|
|
||||||
int temp = PyInt_AsLong(op);
|
|
||||||
Py_XDECREF(op);
|
|
||||||
((INT32*)list)[i] = temp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TYPE_FLOAT32:
|
case TYPE_FLOAT32:
|
||||||
if (PyList_Check(arg)) {
|
for (i = 0; i < n; i++) {
|
||||||
for (i = 0; i < n; i++) {
|
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
dtemp = PyFloat_AsDouble(op);
|
||||||
double temp = PyFloat_AsDouble(op);
|
((FLOAT32*)list)[i] = (FLOAT32) dtemp;
|
||||||
((FLOAT32*)list)[i] = (FLOAT32) temp;
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
PyObject *op = PySequence_GetItem(arg, i);
|
|
||||||
double temp = PyFloat_AsDouble(op);
|
|
||||||
Py_XDECREF(op);
|
|
||||||
((FLOAT32*)list)[i] = (FLOAT32) temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TYPE_DOUBLE:
|
case TYPE_DOUBLE:
|
||||||
if (PyList_Check(arg)) {
|
for (i = 0; i < n; i++) {
|
||||||
for (i = 0; i < n; i++) {
|
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
dtemp = PyFloat_AsDouble(op);
|
||||||
double temp = PyFloat_AsDouble(op);
|
((double*)list)[i] = (double) dtemp;
|
||||||
((double*)list)[i] = temp;
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
PyObject *op = PySequence_GetItem(arg, i);
|
|
||||||
double temp = PyFloat_AsDouble(op);
|
|
||||||
Py_XDECREF(op);
|
|
||||||
((double*)list)[i] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user