Double the speed of list.pop() which was spending most of its time parsing

arguments.
This commit is contained in:
Raymond Hettinger 2004-02-17 11:36:16 +00:00
parent 79b5cf1129
commit 9eb86b3c7c
1 changed files with 11 additions and 2 deletions

View File

@ -772,9 +772,18 @@ static PyObject *
listpop(PyListObject *self, PyObject *args) listpop(PyListObject *self, PyObject *args)
{ {
int i = -1; int i = -1;
PyObject *v; PyObject *v, *arg = NULL;
if (!PyArg_ParseTuple(args, "|i:pop", &i))
if (!PyArg_UnpackTuple(args, "pop", 0, 1, &arg))
return NULL; return NULL;
if (arg != NULL) {
if (PyInt_Check(arg))
i = (int)(PyInt_AS_LONG((PyIntObject*) arg));
else {
PyErr_SetString(PyExc_TypeError, "an integer is required");
return NULL;
}
}
if (self->ob_size == 0) { if (self->ob_size == 0) {
/* Special-case most common failure cause */ /* Special-case most common failure cause */
PyErr_SetString(PyExc_IndexError, "pop from empty list"); PyErr_SetString(PyExc_IndexError, "pop from empty list");