mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-104066: Improve performance of hasattr for module objects (#104063)
This commit is contained in:
parent
c9ecd3ee75
commit
fdcb49c36b
4 changed files with 78 additions and 29 deletions
|
@ -1085,6 +1085,17 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
else if (tp->tp_getattro == (getattrofunc)_Py_module_getattro) {
|
||||
// optimization: suppress attribute error from module getattro method
|
||||
*result = _Py_module_getattro_impl((PyModuleObject*)v, name, 1);
|
||||
if (*result != NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (tp->tp_getattro != NULL) {
|
||||
*result = (*tp->tp_getattro)(v, name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue