mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Optimize list.pop() for the common special case of popping off the end.
More than doubles its speed.
This commit is contained in:
parent
4bb9540dd6
commit
cb3e580ebc
1 changed files with 5 additions and 0 deletions
|
@ -739,6 +739,11 @@ listpop(PyListObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
v = self->ob_item[i];
|
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);
|
Py_INCREF(v);
|
||||||
if (list_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) {
|
if (list_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) {
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue