Commit 25c4e3e0 authored by Stefan Behnel's avatar Stefan Behnel

Simplify specialised GenericGetAttr implementation.

parent 2b0870ba
...@@ -1230,7 +1230,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObj ...@@ -1230,7 +1230,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObj
/////////////// PyObject_GenericGetAttrNoDict.proto /////////////// /////////////// PyObject_GenericGetAttrNoDict.proto ///////////////
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP
static PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else #else
// No-args macro to allow function pointer assignment. // No-args macro to allow function pointer assignment.
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
...@@ -1252,12 +1252,11 @@ static PyObject *__Pyx_RaiseGenericAttributeError(PyTypeObject *tp, PyObject *at ...@@ -1252,12 +1252,11 @@ static PyObject *__Pyx_RaiseGenericAttributeError(PyTypeObject *tp, PyObject *at
return NULL; return NULL;
} }
static PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
// Copied and adapted from _PyObject_GenericGetAttrWithDict() in CPython 2.6/3.7. // Copied and adapted from _PyObject_GenericGetAttrWithDict() in CPython 2.6/3.7.
// To be used in the "tp_getattro" slot of extension types that have no instance dict and cannot be subclassed. // To be used in the "tp_getattro" slot of extension types that have no instance dict and cannot be subclassed.
PyObject *descr, *res; PyObject *descr;
PyTypeObject *tp = Py_TYPE(obj); PyTypeObject *tp = Py_TYPE(obj);
descrgetfunc f = NULL;
if (unlikely(!PyString_Check(attr_name))) { if (unlikely(!PyString_Check(attr_name))) {
return PyObject_GenericGetAttr(obj, attr_name); return PyObject_GenericGetAttr(obj, attr_name);
...@@ -1265,29 +1264,25 @@ static PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* at ...@@ -1265,29 +1264,25 @@ static PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* at
assert(!tp->tp_dictoffset); assert(!tp->tp_dictoffset);
descr = _PyType_Lookup(tp, attr_name); descr = _PyType_Lookup(tp, attr_name);
if (descr if (unlikely(!descr)) {
return __Pyx_RaiseGenericAttributeError(tp, attr_name);
}
Py_INCREF(descr);
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
&& likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)) if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
#endif #endif
) { {
f = Py_TYPE(descr)->tp_descr_get; descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
// Optimise for the non-descriptor case because it is faster. // Optimise for the non-descriptor case because it is faster.
if (unlikely(f)) { if (unlikely(f)) {
Py_INCREF(descr); PyObject *res = f(descr, obj, (PyObject *)tp);
res = f(descr, obj, (PyObject *)tp);
Py_DECREF(descr); Py_DECREF(descr);
goto done; return res;
}
} }
if (likely(descr)) {
Py_INCREF(descr);
res = descr;
goto done;
} }
return descr;
return __Pyx_RaiseGenericAttributeError(tp, attr_name);
done:
return res;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment