mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-92216: improve performance of hasattr for type objects (GH-99979)
This commit is contained in:
parent
49f6ff719c
commit
7fc7909677
4 changed files with 44 additions and 8 deletions
|
|
@ -939,7 +939,15 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
if (tp->tp_getattro != NULL) {
|
||||
if (tp->tp_getattro == (getattrofunc)_Py_type_getattro) {
|
||||
int supress_missing_attribute_exception = 0;
|
||||
*result = _Py_type_getattro_impl((PyTypeObject*)v, name, &supress_missing_attribute_exception);
|
||||
if (supress_missing_attribute_exception) {
|
||||
// return 0 without having to clear the exception
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (tp->tp_getattro != NULL) {
|
||||
*result = (*tp->tp_getattro)(v, name);
|
||||
}
|
||||
else if (tp->tp_getattr != NULL) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue