From bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 11 Dec 2018 08:28:18 +0200 Subject: 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". --- Objects/methodobject.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Objects/methodobject.c') diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 6dec64276d..9fed3fca99 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -104,16 +104,13 @@ meth_dealloc(PyCFunctionObject *m) static PyObject * meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) { - PyObject *builtins; - PyObject *getattr; _Py_IDENTIFIER(getattr); if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); - builtins = PyEval_GetBuiltins(); - getattr = _PyDict_GetItemId(builtins, &PyId_getattr); - return Py_BuildValue("O(Os)", getattr, m->m_self, m->m_ml->ml_name); + return Py_BuildValue("N(Os)", _PyEval_GetBuiltinId(&PyId_getattr), + m->m_self, m->m_ml->ml_name); } static PyMethodDef meth_methods[] = { -- cgit v1.2.1