mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Optimize reversed(list) using a custom iterator.
This commit is contained in:
parent
ff1f194982
commit
1021c44b41
2 changed files with 98 additions and 4 deletions
|
@ -174,8 +174,8 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq))
|
||||
return NULL;
|
||||
|
||||
/* Special case optimization for xrange */
|
||||
if (PyRange_Check(seq))
|
||||
/* Special case optimization for xrange and lists */
|
||||
if (PyRange_Check(seq) || PyList_Check(seq))
|
||||
return PyObject_CallMethod(seq, "__reversed__", NULL);
|
||||
|
||||
if (!PySequence_Check(seq)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue