summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-02-17 11:36:16 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-02-17 11:36:16 (GMT)
commit9eb86b3c7cd44831735392f67ae3d97f859271ba (patch)
tree86b0ff93f942960d040833c279a36bf81f08d251
parent79b5cf112932dd2e3dd14bc9be3f45db88d7faa4 (diff)
downloadcpython-9eb86b3c7cd44831735392f67ae3d97f859271ba.zip
cpython-9eb86b3c7cd44831735392f67ae3d97f859271ba.tar.gz
cpython-9eb86b3c7cd44831735392f67ae3d97f859271ba.tar.bz2
Double the speed of list.pop() which was spending most of its time parsing
arguments.
-rw-r--r--Objects/listobject.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 1bf0b80..7289be1 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");