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".
diff --git a/Objects/setobject.c b/Objects/setobject.c
index c2a1467..a43ecd5 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -842,6 +842,7 @@
static PyObject *
setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored))
{
+ _Py_IDENTIFIER(iter);
/* copy the iterator state */
setiterobject tmp = *si;
Py_XINCREF(tmp.si_set);
@@ -852,7 +853,7 @@
if (list == NULL) {
return NULL;
}
- return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
+ return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");