mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-93955: Use unbound methods for slot __getattr__
and __getattribute__
(GH-93956)
This commit is contained in:
parent
7a2cc35e1c
commit
fea1e9bc5c
2 changed files with 9 additions and 1 deletions
|
@ -0,0 +1 @@
|
|||
Improve performance of attribute lookups on objects with custom ``__getattribute__`` and ``__getattr__``. Patch by Ken Jin.
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue