summaryrefslogtreecommitdiffstats
path: root/Include/object.h
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2018-01-16 11:52:41 (GMT)
committerGitHub <noreply@github.com>2018-01-16 11:52:41 (GMT)
commit378edee0a3b913d60653dc17dfe61d83405a8135 (patch)
treee91c9b9b446aa0ce076da778bde6c1da27ff5e23 /Include/object.h
parentb44c5169f64178d2ff2914187b315549e7ab0cb6 (diff)
downloadcpython-378edee0a3b913d60653dc17dfe61d83405a8135.zip
cpython-378edee0a3b913d60653dc17dfe61d83405a8135.tar.gz
cpython-378edee0a3b913d60653dc17dfe61d83405a8135.tar.bz2
bpo-32544: Speed up hasattr() and getattr() (GH-5173)
AttributeError was raised always when attribute is not found. This commit skip raising AttributeError when `tp_getattro` is `PyObject_GenericGetAttr`. It makes hasattr() and getattr() about 4x faster when attribute is not found.
Diffstat (limited to 'Include/object.h')
-rw-r--r--Include/object.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/Include/object.h b/Include/object.h
index 7db5bfe..274b676 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -536,6 +536,8 @@ PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *);
+/* Same as PyObject_GetAttr(), but don't raise AttributeError. */
+PyAPI_FUNC(PyObject *) _PyObject_GetAttrWithoutError(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
@@ -567,7 +569,7 @@ PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
dict as the last parameter. */
PyAPI_FUNC(PyObject *)
-_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
+_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *, int);
PyAPI_FUNC(int)
_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
PyObject *, PyObject *);