summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-05-03 02:28:04 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-05-03 02:28:04 (GMT)
commit501182a47b722a02edd83a344ba53d06cd9afbd1 (patch)
tree3788bfd3a2d8ae11f76c0836d4905238e65f1278 /Modules
parent51454a62e235f27c28a24620c3df002d4076b57c (diff)
downloadcpython-501182a47b722a02edd83a344ba53d06cd9afbd1.zip
cpython-501182a47b722a02edd83a344ba53d06cd9afbd1.tar.gz
cpython-501182a47b722a02edd83a344ba53d06cd9afbd1.tar.bz2
just sort the items tuple directly (closes #24094)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_json.c30
1 files changed, 3 insertions, 27 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index 397037e..6df08b5 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1527,35 +1527,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);
- 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)