Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-140009: Optimize dict object by replacing PyTuple_Pack with PyTupl…
…e_FromArray
  • Loading branch information
rashes2006 committed Feb 5, 2026
commit 174a82b575f91ec17d879707b33f4c62d8be8905
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of dict object by replacing PyTuple_Pack with PyTuple_FromArray for small tuples.
6 changes: 4 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5083,7 +5083,8 @@ dictiter_new(PyDictObject *dict, PyTypeObject *itertype)
}
if (itertype == &PyDictIterItem_Type ||
itertype == &PyDictRevIterItem_Type) {
di->di_result = PyTuple_Pack(2, Py_None, Py_None);
PyObject *items[] = {Py_None, Py_None};
di->di_result = PyTuple_FromArray(items, 2);
if (di->di_result == NULL) {
Py_DECREF(di);
return NULL;
Expand Down Expand Up @@ -6284,7 +6285,8 @@ dictitems_xor_lock_held(PyObject *d1, PyObject *d2)
}
}
else {
PyObject *pair = PyTuple_Pack(2, key, val2);
PyObject *items[] = {key, val2};
PyObject *pair = PyTuple_FromArray(items, 2);
if (pair == NULL) {
goto error;
}
Expand Down
Loading