diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-05-03 02:36:26 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-05-03 02:36:26 (GMT) |
commit | 122f4b1bda8262ace6aa021935e8c605a17c3748 (patch) | |
tree | fbe4e3303a9900d7c469786d12a8786d2f224c96 /Modules | |
parent | 0a9933ebf3704540a5f31225b26acb990e1de4bf (diff) | |
parent | 501182a47b722a02edd83a344ba53d06cd9afbd1 (diff) | |
download | cpython-122f4b1bda8262ace6aa021935e8c605a17c3748.zip cpython-122f4b1bda8262ace6aa021935e8c605a17c3748.tar.gz cpython-122f4b1bda8262ace6aa021935e8c605a17c3748.tar.bz2 |
merge 3.3 (#24094)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_json.c | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index f523aab..f87d680 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1541,36 +1541,11 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc, */ } - if (PyObject_IsTrue(s->sort_keys)) { - /* First sort the keys then replace them with (key, value) tuples. */ - Py_ssize_t i, nitems; - items = PyMapping_Keys(dct); - if (items == NULL) - goto bail; - if (!PyList_Check(items)) { - PyErr_SetString(PyExc_ValueError, "keys must return list"); - goto bail; - } - if (PyList_Sort(items) < 0) - goto bail; - nitems = PyList_GET_SIZE(items); - for (i = 0; i < nitems; i++) { - PyObject *key, *value; - key = PyList_GET_ITEM(items, i); - value = PyDict_GetItem(dct, key); - item = PyTuple_Pack(2, key, value); - if (item == NULL) - goto bail; - PyList_SET_ITEM(items, i, item); - item = NULL; - Py_DECREF(key); - } - } - else { - items = PyMapping_Items(dct); - } + items = PyMapping_Items(dct); if (items == NULL) goto bail; + if (PyObject_IsTrue(s->sort_keys) && PyList_Sort(items) < 0) + goto bail; it = PyObject_GetIter(items); Py_DECREF(items); if (it == NULL) |