diff --git a/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst b/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst new file mode 100644 index 00000000000000..08fe44d66f8938 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-12-11-20-00.gh-issue-140009.json.rst @@ -0,0 +1 @@ +Optimize :mod:`json` decoding with ``object_pairs_hook`` by using :c:func:`PyTuple_FromArray` instead of :c:func:`PyTuple_Pack`. diff --git a/Modules/_json.c b/Modules/_json.c index c7e62c4fe55c64..8189df81576dcc 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -806,7 +806,8 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss goto bail; if (has_pairs_hook) { - PyObject *item = PyTuple_Pack(2, key, val); + PyObject *items[] = {key, val}; + PyObject *item = PyTuple_FromArray(items, 2); if (item == NULL) goto bail; Py_CLEAR(key);