diff options
author | Raymond Hettinger <python@rcn.com> | 2004-02-17 11:36:16 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-02-17 11:36:16 +0000 |
commit | 16a395ef1e0e8f94191ac8e86b680888f746a02a (patch) | |
tree | 9d0a403f3b72b021811c2a4c8107001da3f7eb93 | |
parent | 0e0f82e87c55b4fd95ae2675eea6b2c76f3d4294 (diff) | |
download | cpython-16a395ef1e0e8f94191ac8e86b680888f746a02a.tar.gz |
Double the speed of list.pop() which was spending most of its time parsing
arguments.
-rw-r--r-- | Objects/listobject.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 1bf0b80a3a..7289be1286 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -772,9 +772,18 @@ static PyObject * listpop(PyListObject *self, PyObject *args) { int i = -1; - PyObject *v; - if (!PyArg_ParseTuple(args, "|i:pop", &i)) + PyObject *v, *arg = NULL; + + if (!PyArg_UnpackTuple(args, "pop", 0, 1, &arg)) 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) { /* Special-case most common failure cause */ PyErr_SetString(PyExc_IndexError, "pop from empty list"); |