mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +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*
|
||||
getlist(PyObject* arg, int* length, const char* wrong_length, int type)
|
||||
{
|
||||
int i, n;
|
||||
int i, n, itemp;
|
||||
double dtemp;
|
||||
void* list;
|
||||
|
||||
PyObject* seq;
|
||||
PyObject* op;
|
||||
|
||||
if (!PySequence_Check(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||
return NULL;
|
||||
|
@ -383,70 +386,41 @@ getlist(PyObject* arg, int* length, const char* wrong_length, int type)
|
|||
if (!list)
|
||||
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) {
|
||||
case TYPE_UINT8:
|
||||
if (PyList_Check(arg)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
||||
int temp = PyInt_AsLong(op);
|
||||
((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);
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||
itemp = PyInt_AsLong(op);
|
||||
((UINT8*)list)[i] = CLIP(itemp);
|
||||
}
|
||||
break;
|
||||
case TYPE_INT32:
|
||||
if (PyList_Check(arg)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
||||
int temp = PyInt_AsLong(op);
|
||||
((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;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||
itemp = PyInt_AsLong(op);
|
||||
((INT32*)list)[i] = itemp;
|
||||
}
|
||||
break;
|
||||
case TYPE_FLOAT32:
|
||||
if (PyList_Check(arg)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
||||
double temp = PyFloat_AsDouble(op);
|
||||
((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;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||
dtemp = PyFloat_AsDouble(op);
|
||||
((FLOAT32*)list)[i] = (FLOAT32) dtemp;
|
||||
}
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if (PyList_Check(arg)) {
|
||||
for (i = 0; i < n; i++) {
|
||||
PyObject *op = PyList_GET_ITEM(arg, i);
|
||||
double temp = PyFloat_AsDouble(op);
|
||||
((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;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||
dtemp = PyFloat_AsDouble(op);
|
||||
((double*)list)[i] = (double) dtemp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user