mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00: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
|
|
@ -1080,23 +1080,6 @@ PyObject_SelfIter(PyObject *obj)
|
|||
return obj;
|
||||
}
|
||||
|
||||
/* Convenience function to get a builtin from its name */
|
||||
PyObject *
|
||||
_PyObject_GetBuiltin(const char *name)
|
||||
{
|
||||
PyObject *mod_name, *mod, *attr;
|
||||
|
||||
mod_name = _PyUnicode_FromId(&PyId_builtins); /* borrowed */
|
||||
if (mod_name == NULL)
|
||||
return NULL;
|
||||
mod = PyImport_Import(mod_name);
|
||||
if (mod == NULL)
|
||||
return NULL;
|
||||
attr = PyObject_GetAttrString(mod, name);
|
||||
Py_DECREF(mod);
|
||||
return attr;
|
||||
}
|
||||
|
||||
/* Helper used when the __next__ method is removed from a type:
|
||||
tp_iternext is never NULL and can be safely called without checking
|
||||
on every iteration.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue