https://github.com/python/cpython/commit/e6aa5152964647e548929a10d2d0fe2a7c5d875a
commit: e6aa5152964647e548929a10d2d0fe2a7c5d875a
branch: main
author: Pieter Eendebak <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-10-13T15:58:25+05:30
summary:

gh-140009: Improve performance of `list_extend_dictitems` by using 
`PyTuple_FromArray` (#140010)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-18-54-06.gh-issue-140009.-MbFh_.rst
M Objects/listobject.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-18-54-06.gh-issue-140009.-MbFh_.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-18-54-06.gh-issue-140009.-MbFh_.rst
new file mode 100644
index 00000000000000..97b35c88e17e37
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-12-18-54-06.gh-issue-140009.-MbFh_.rst
@@ -0,0 +1 @@
+Improve performance of list extension by dictionary items.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index b2903e5c93ee9f..1722ea60cdc68f 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -1382,9 +1382,9 @@ list_extend_dictitems(PyListObject *self, PyDictObject 
*dict)
     PyObject **dest = self->ob_item + m;
     Py_ssize_t pos = 0;
     Py_ssize_t i = 0;
-    PyObject *key, *value;
-    while (_PyDict_Next((PyObject *)dict, &pos, &key, &value, NULL)) {
-        PyObject *item = PyTuple_Pack(2, key, value);
+    PyObject *key_value[2];
+    while (_PyDict_Next((PyObject *)dict, &pos, &key_value[0], &key_value[1], 
NULL)) {
+        PyObject *item = PyTuple_FromArray(key_value, 2);
         if (item == NULL) {
             Py_SET_SIZE(self, m + i);
             return -1;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to