]> granicus.if.org Git - python/commitdiff
Optimize list.pop() for the common special case of popping off the end.
authorRaymond Hettinger <python@rcn.com>
Fri, 13 Feb 2004 18:36:31 +0000 (18:36 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 13 Feb 2004 18:36:31 +0000 (18:36 +0000)
More than doubles its speed.

Objects/listobject.c

index 5bc4577e56f53cfad8fb66d76bfc6d85872439d8..66519662821fc08ba5423e6e5f623992904b145c 100644 (file)
@@ -739,6 +739,11 @@ listpop(PyListObject *self, PyObject *args)
                return NULL;
        }
        v = self->ob_item[i];
+       if (i == self->ob_size - 1) {
+               if (list_resize(self, self->ob_size - 1) == -1)
+                       return NULL;
+               return v;
+       }
        Py_INCREF(v);
        if (list_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) {
                Py_DECREF(v);