Commit 6cbc8016 authored by Stefan Behnel's avatar Stefan Behnel

use pre-instantiated strings in __Pyx_setup_reduce() to reduce overhead - we...

use pre-instantiated strings in __Pyx_setup_reduce() to reduce overhead - we will most likely need and indefinitely store them in the types anyway
parent 6cd7c8f3
...@@ -57,14 +57,16 @@ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) { ...@@ -57,14 +57,16 @@ static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
static int __Pyx_setup_reduce(PyObject* type_obj); static int __Pyx_setup_reduce(PyObject* type_obj);
/////////////// SetupReduce /////////////// /////////////// SetupReduce ///////////////
//@requires: ObjectHandling.c::PyObjectGetAttrStr
#define __Pyx_setup_reduce_GET_ATTR_OR_BAD(res, obj, name) res = PyObject_GetAttrString(obj, name); if (res == NULL) goto BAD; #define __Pyx_setup_reduce_GET_ATTR_OR_BAD(res, obj, name) \
res = __Pyx_PyObject_GetAttrStr(obj, name); if (unlikely(!res)) goto BAD;
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
int ret; int ret;
PyObject *name_attr; PyObject *name_attr;
name_attr = PyObject_GetAttrString(meth, "__name__"); name_attr = __Pyx_PyObject_GetAttrStr(meth, PYIDENT("__name__"));
if (name_attr) { if (name_attr) {
ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
} else { } else {
...@@ -91,28 +93,28 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { ...@@ -91,28 +93,28 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
PyObject *setstate = NULL; PyObject *setstate = NULL;
PyObject *setstate_cython = NULL; PyObject *setstate_cython = NULL;
if (PyObject_HasAttrString(type_obj, "__getstate__")) goto GOOD; if (PyObject_HasAttr(type_obj, PYIDENT("__getstate__"))) goto GOOD;
if (object_reduce_ex == NULL) { if (object_reduce_ex == NULL) {
__Pyx_setup_reduce_GET_ATTR_OR_BAD(builtin_object, __pyx_b, "object"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(builtin_object, __pyx_b, PYIDENT("object"));
__Pyx_setup_reduce_GET_ATTR_OR_BAD(object_reduce, builtin_object, "__reduce__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(object_reduce, builtin_object, PYIDENT("__reduce__"));
__Pyx_setup_reduce_GET_ATTR_OR_BAD(object_reduce_ex, builtin_object, "__reduce_ex__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(object_reduce_ex, builtin_object, PYIDENT("__reduce_ex__"));
} }
__Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce_ex, type_obj, "__reduce_ex__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce_ex, type_obj, PYIDENT("__reduce_ex__"));
if (reduce_ex == object_reduce_ex) { if (reduce_ex == object_reduce_ex) {
__Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce, type_obj, "__reduce__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce, type_obj, PYIDENT("__reduce__"));
if (object_reduce == reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) { if (object_reduce == reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) {
__Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce_cython, type_obj, "__reduce_cython__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(reduce_cython, type_obj, PYIDENT("__reduce_cython__"));
ret = PyDict_SetItemString(((PyTypeObject*)type_obj)->tp_dict, "__reduce__", reduce_cython); if (ret < 0) goto BAD; ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce__"), reduce_cython); if (ret < 0) goto BAD;
ret = PyDict_DelItemString(((PyTypeObject*)type_obj)->tp_dict, "__reduce_cython__"); if (ret < 0) goto BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce_cython__")); if (ret < 0) goto BAD;
setstate = PyObject_GetAttrString(type_obj, "__setstate__"); setstate = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__setstate__"));
if (!setstate) PyErr_Clear(); if (!setstate) PyErr_Clear();
if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) { if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) {
__Pyx_setup_reduce_GET_ATTR_OR_BAD(setstate_cython, type_obj, "__setstate_cython__"); __Pyx_setup_reduce_GET_ATTR_OR_BAD(setstate_cython, type_obj, PYIDENT("__setstate_cython__"));
ret = PyDict_SetItemString(((PyTypeObject*)type_obj)->tp_dict, "__setstate__", setstate_cython); if (ret < 0) goto BAD; ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate__"), setstate_cython); if (ret < 0) goto BAD;
ret = PyDict_DelItemString(((PyTypeObject*)type_obj)->tp_dict, "__setstate_cython__"); if (ret < 0) goto BAD; ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate_cython__")); if (ret < 0) goto BAD;
} }
PyType_Modified((PyTypeObject*)type_obj); PyType_Modified((PyTypeObject*)type_obj);
} }
...@@ -120,7 +122,8 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { ...@@ -120,7 +122,8 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
goto GOOD; goto GOOD;
BAD: BAD:
if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); if (!PyErr_Occurred())
PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name);
ret = -1; ret = -1;
GOOD: GOOD:
Py_XDECREF(builtin_object); Py_XDECREF(builtin_object);
......
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