From: Raymond Hettinger Date: Fri, 13 Feb 2004 18:36:31 +0000 (+0000) Subject: Optimize list.pop() for the common special case of popping off the end. X-Git-Tag: v2.4a1~824 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb3e580ebce784c2e5eb86cb30c842f66e29cb04;p=python Optimize list.pop() for the common special case of popping off the end. More than doubles its speed. --- diff --git a/Objects/listobject.c b/Objects/listobject.c index 5bc4577e56..6651966282 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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);