Skip to content

Commit

Permalink
gh-93955: Use unbound methods for slot __getattr__ and `__getattrib…
Browse files Browse the repository at this point in the history
…ute__` (GH-93956)
  • Loading branch information
Fidget-Spinner committed Jun 18, 2022
1 parent 7a2cc35 commit fea1e9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of attribute lookups on objects with custom ``__getattribute__`` and ``__getattr__``. Patch by Ken Jin.
9 changes: 8 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fea1e9b

Please sign in to comment.