mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-104078: Improve performance of PyObject_HasAttrString (#104079)
This commit is contained in:
parent
fdb3ef8c0f
commit
8d34031068
2 changed files with 18 additions and 6 deletions
|
|
@ -0,0 +1 @@
|
|||
Improve the performance of :c:func:`PyObject_HasAttrString`
|
||||
|
|
@ -918,13 +918,24 @@ PyObject_GetAttrString(PyObject *v, const char *name)
|
|||
int
|
||||
PyObject_HasAttrString(PyObject *v, const char *name)
|
||||
{
|
||||
PyObject *res = PyObject_GetAttrString(v, name);
|
||||
if (res != NULL) {
|
||||
Py_DECREF(res);
|
||||
return 1;
|
||||
if (Py_TYPE(v)->tp_getattr != NULL) {
|
||||
PyObject *res = (*Py_TYPE(v)->tp_getattr)(v, (char*)name);
|
||||
if (res != NULL) {
|
||||
Py_DECREF(res);
|
||||
return 1;
|
||||
}
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
|
||||
PyObject *attr_name = PyUnicode_FromString(name);
|
||||
if (attr_name == NULL) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
int ok = PyObject_HasAttr(v, attr_name);
|
||||
Py_DECREF(attr_name);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue