From cb3e580ebce784c2e5eb86cb30c842f66e29cb04 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 13 Feb 2004 18:36:31 +0000 Subject: [PATCH] Optimize list.pop() for the common special case of popping off the end. More than doubles its speed. --- Objects/listobject.c | 5 +++++ 1 file changed, 5 insertions(+) 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); -- 2.50.1