Skip to content

Commit

Permalink
Removed support for __json__ method on str
Browse files Browse the repository at this point in the history
This functionality caused a performance regression without a use-case
justifying the trade-off.
  • Loading branch information
Jahaja committed Feb 6, 2017
1 parent 53f85b1 commit 5f98f01
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions python/objToJSON.c
Expand Up @@ -229,21 +229,6 @@ static void *PyDateToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size
return NULL;
}

static int PyHasAttrStringPreserveErr(PyObject *obj, const char *attr)
{
int res;
PyObject *excType = NULL, *excValue, *excTraceback;

if (!PyErr_Occurred())
return PyObject_HasAttrString(obj, "__json__");

PyErr_Fetch(&excType, &excValue, &excTraceback);
res = PyObject_HasAttrString(obj, "__json__");
PyErr_Restore(excType, excValue, excTraceback);

return res;
}

static int Tuple_iterNext(JSOBJ obj, JSONTypeContext *tc)
{
PyObject *item;
Expand Down Expand Up @@ -593,7 +578,7 @@ static void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc, JSONObject
return;
}
else
if (PyString_Check(obj) && LIKELY(!PyHasAttrStringPreserveErr(obj, "__json__")))
if (PyString_Check(obj))
{
PRINTMARK();
pc->PyTypeToJSON = PyStringToUTF8; tc->type = JT_UTF8;
Expand Down

0 comments on commit 5f98f01

Please sign in to comment.