diff options
author | wangxiang-hz <34048878+wangxiang-hz@users.noreply.github.com> | 2023-03-11 11:11:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 11:11:37 (GMT) |
commit | aa0a73d1bc53dcb6348a869df1e775138991e561 (patch) | |
tree | 66ad74f8d199076d88e5150b999895cd15807560 /Objects/object.c | |
parent | 5ffdaf748d98da6065158534720f1996a45a0072 (diff) | |
download | cpython-aa0a73d1bc53dcb6348a869df1e775138991e561.zip cpython-aa0a73d1bc53dcb6348a869df1e775138991e561.tar.gz cpython-aa0a73d1bc53dcb6348a869df1e775138991e561.tar.bz2 |
gh-102213: Optimize the performance of `__getattr__` (GH-102248)
When __getattr__ is defined, python with try to find an attribute using _PyObject_GenericGetAttrWithDict
find nothing is reasonable so we don't need an exception, it will hurt performance.
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 38da4d4..dff5e2a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1405,6 +1405,12 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name) return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 0); } +PyObject * +_PyObject_GenericTryGetAttr(PyObject *obj, PyObject *name) +{ + return _PyObject_GenericGetAttrWithDict(obj, name, NULL, 1); +} + int _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, PyObject *value, PyObject *dict) |