mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-35444: Unify and optimize the helper for getting a builtin object. (GH-11047)
This speeds up pickling of some iterators. This fixes also error handling in pickling methods when fail to look up builtin "getattr".
This commit is contained in:
parent
7cf3d8e251
commit
bb86bf4c4e
21 changed files with 68 additions and 72 deletions
|
|
@ -3356,23 +3356,25 @@ listreviter_setstate(listreviterobject *it, PyObject *state)
|
|||
static PyObject *
|
||||
listiter_reduce_general(void *_it, int forward)
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
_Py_IDENTIFIER(reversed);
|
||||
PyObject *list;
|
||||
|
||||
/* the objects are not the same, index is of different types! */
|
||||
if (forward) {
|
||||
listiterobject *it = (listiterobject *)_it;
|
||||
if (it->it_seq)
|
||||
return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("iter"),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
it->it_seq, it->it_index);
|
||||
} else {
|
||||
listreviterobject *it = (listreviterobject *)_it;
|
||||
if (it->it_seq)
|
||||
return Py_BuildValue("N(O)n", _PyObject_GetBuiltin("reversed"),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed),
|
||||
it->it_seq, it->it_index);
|
||||
}
|
||||
/* empty iterator, create an empty list */
|
||||
list = PyList_New(0);
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue