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:
Serhiy Storchaka 2018-12-11 08:28:18 +02:00 committed by GitHub
parent 7cf3d8e251
commit bb86bf4c4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 68 additions and 72 deletions

View file

@ -1806,6 +1806,7 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling");
static PyObject *
odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(iter);
/* copy the iterator state */
odictiterobject tmp = *di;
Py_XINCREF(tmp.di_odict);
@ -1818,7 +1819,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored))
if (list == NULL) {
return NULL;
}
return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
}
static PyMethodDef odictiter_methods[] = {