diff options
author | Itamar Ostricher <itamarost@gmail.com> | 2023-05-04 14:50:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 14:50:26 (GMT) |
commit | fdcb49c36b2ed8347d8d9f2dcd7052cc90207beb (patch) | |
tree | eacef8a2b7d8ee2aeb46efff8750315f2263fb16 /Objects/object.c | |
parent | c9ecd3ee75b472bb0a7538e0288c5cfea146da83 (diff) | |
download | cpython-fdcb49c36b2ed8347d8d9f2dcd7052cc90207beb.zip cpython-fdcb49c36b2ed8347d8d9f2dcd7052cc90207beb.tar.gz cpython-fdcb49c36b2ed8347d8d9f2dcd7052cc90207beb.tar.bz2 |
gh-104066: Improve performance of hasattr for module objects (#104063)
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index c6ef592..41c52e2 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1085,6 +1085,17 @@ _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result) return 0; } } + else if (tp->tp_getattro == (getattrofunc)_Py_module_getattro) { + // optimization: suppress attribute error from module getattro method + *result = _Py_module_getattro_impl((PyModuleObject*)v, name, 1); + if (*result != NULL) { + return 1; + } + if (PyErr_Occurred()) { + return -1; + } + return 0; + } else if (tp->tp_getattro != NULL) { *result = (*tp->tp_getattro)(v, name); } |