Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
optimize implementation according to Fidget-Spinner's advise
  • Loading branch information
wangxiang-hz committed Mar 10, 2023
commit f95d84421dc91ad6bc51d7b8792bc1633964b9b5
1 change: 1 addition & 0 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
extern int _PyType_HasSubclasses(PyTypeObject *);
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
extern PyObject* _PyObject_GenericTryGetAttr(PyObject *, PyObject *);

// Access macro to the members which are floating "behind" the object
static inline PyMemberDef* _PyHeapType_GET_MEMBERS(PyHeapTypeObject *etype) {
Expand Down
1 change: 0 additions & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyObject_GenericTryGetAttr(PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *, PyObject *, PyObject *);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(int) PyObject_GenericSetDict(PyObject *, PyObject *, void *);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix performance loss when accessing an object's attributes with `__getattr__` defined.
Fix performance loss when accessing an object's attributes with ``__getattr__`` defined.
2 changes: 1 addition & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
}

PyObject *
PyObject_GenericTryGetAttr(PyObject *obj, PyObject *name)
_PyObject_GenericTryGetAttr(PyObject *obj, PyObject *name)
{
return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 1);
}
Expand Down
5 changes: 3 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -8249,15 +8249,16 @@ _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name)
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
(void *)PyObject_GenericGetAttr))
/* finding nothing is reasonable when __getattr__ is defined */
res = PyObject_GenericTryGetAttr(self, name);
res = _PyObject_GenericTryGetAttr(self, name);
else {
Py_INCREF(getattribute);
res = call_attribute(self, getattribute, name);
Py_DECREF(getattribute);
}
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError))
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
}
res = call_attribute(self, getattr, name);
}
Py_DECREF(getattr);
Expand Down