mirror of
https://github.com/python/cpython.git
synced 2026-01-06 23:42:34 +00:00
gh-102213: Optimize the performance of __getattr__ (GH-103761)
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Xiang Wang <34048878+wangxiang-hz@users.noreply.github.com>
This commit is contained in:
parent
487f55d580
commit
59c27fa5cb
3 changed files with 28 additions and 8 deletions
|
|
@ -8306,17 +8306,23 @@ _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name)
|
|||
if (getattribute == NULL ||
|
||||
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
|
||||
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
|
||||
(void *)PyObject_GenericGetAttr))
|
||||
res = PyObject_GenericGetAttr(self, name);
|
||||
else {
|
||||
(void *)PyObject_GenericGetAttr)) {
|
||||
res = _PyObject_GenericGetAttrWithDict(self, name, NULL, 1);
|
||||
/* if res == NULL with no exception set, then it must be an
|
||||
AttributeError suppressed by us. */
|
||||
if (res == NULL && !PyErr_Occurred()) {
|
||||
res = call_attribute(self, getattr, name);
|
||||
}
|
||||
} else {
|
||||
Py_INCREF(getattribute);
|
||||
res = call_attribute(self, getattribute, name);
|
||||
Py_DECREF(getattribute);
|
||||
if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
res = call_attribute(self, getattr, name);
|
||||
}
|
||||
}
|
||||
if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
PyErr_Clear();
|
||||
res = call_attribute(self, getattr, name);
|
||||
}
|
||||
|
||||
Py_DECREF(getattr);
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue