summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-02-13 18:36:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-02-13 18:36:31 (GMT)
commitcb3e580ebce784c2e5eb86cb30c842f66e29cb04 (patch)
tree4ec6bf0316cd4a3f9f94deb9dd75b8be44ddc995 /Objects
parent4bb9540dd6eddaf60b908796c2412696a8870bd1 (diff)
downloadcpython-cb3e580ebce784c2e5eb86cb30c842f66e29cb04.zip
cpython-cb3e580ebce784c2e5eb86cb30c842f66e29cb04.tar.gz
cpython-cb3e580ebce784c2e5eb86cb30c842f66e29cb04.tar.bz2
Optimize list.pop() for the common special case of popping off the end.
More than doubles its speed.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/listobject.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 5bc4577..6651966 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);