New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

In issue32544 there was introduced a new private C API function 
_PyObject_GetAttrWithoutError() which never raises an AttributeError, but 
returns NULL without error set if an attribute is absent. This allowed to speed 
up Python builtins hasattr() and getattr() with the default argument.

But C code also could gain a benefit from this. It is common to look up an 
attribute and silence an AttributeError. Actually it is more common than the 
opposite case.

The proposed patch adds yet one function, _PyObject_GetAttrIdWithoutError(), 
and uses these two functions if it is possible to avoid checking an 
AttributeError after PyObject_GetAttr() and _PyObject_GetAttrId(). This could 
speed up some code, and also makes it cleaner.

----------
components: Extension Modules, Interpreter Core
messages: 310101
nosy: inada.naoki, serhiy.storchaka, vstinner
priority: normal
severity: normal
status: open
title: Speed up and clean up getting optional attributes in C code
type: performance
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32571>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to