gh-93955: Use unbound methods for slot `__getattr__` and `__getattribute__` (GH-93956)

This commit is contained in:
Ken Jin 2022-06-18 22:42:42 +08:00 committed by GitHub
parent 7a2cc35e1c
commit fea1e9bc5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -0,0 +1 @@
Improve performance of attribute lookups on objects with custom ``__getattribute__`` and ``__getattr__``. Patch by Ken Jin.

View File

@ -7782,10 +7782,17 @@ slot_tp_getattro(PyObject *self, PyObject *name)
return vectorcall_method(&_Py_ID(__getattribute__), stack, 2);
}
static PyObject *
static inline PyObject *
call_attribute(PyObject *self, PyObject *attr, PyObject *name)
{
PyObject *res, *descr = NULL;
if (_PyType_HasFeature(Py_TYPE(attr), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
PyObject *args[] = { self, name };
res = PyObject_Vectorcall(attr, args, 2, NULL);
return res;
}
descrgetfunc f = Py_TYPE(attr)->tp_descr_get;
if (f != NULL) {