]> granicus.if.org Git - python/commitdiff
Double the speed of list.pop() which was spending most of its time parsing
authorRaymond Hettinger <python@rcn.com>
Tue, 17 Feb 2004 11:36:16 +0000 (11:36 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 17 Feb 2004 11:36:16 +0000 (11:36 +0000)
arguments.

Objects/listobject.c

index 1bf0b80a3a85b8933fe11d8b311f44533c9a0552..7289be1286fdd47d2cc7f901edf727573844a2ff 100644 (file)
@@ -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");