https://github.com/python/cpython/commit/1e406e6d24dc6e688451db4f0719057178feb0b8
commit: 1e406e6d24dc6e688451db4f0719057178feb0b8
branch: main
author: Pieter Eendebak <[email protected]>
committer: eendebakpt <[email protected]>
date: 2026-10-30T09:51:38+01:00
summary:

gh-160913: Use the dict freelist in dict() (#160922)

Use the dict freelist in dict()

dict_vectorcall() allocated every instance with _PyType_AllocNoTrack(),
so dict() never reused the objects that {} and PyDict_New() recycle
through the freelist. Allocate with PyDict_New() instead. tp_vectorcall
is not inherited by subclasses, so dict_vectorcall() only ever runs for
the exact dict type; assert that rather than checking it.

Co-authored-by: Claude Fable 5.1 <[email protected]>

files:
M Objects/dictobject.c

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 1c3b98032b8af1..9d06afbca8066c 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -5415,7 +5415,8 @@ dict_vectorcall(PyObject *type, PyObject * const*args,
         return NULL;
     }
 
-    PyObject *self = dict_new(_PyType_CAST(type), NULL, NULL);
+    assert(type == (PyObject *)&PyDict_Type);
+    PyObject *self = PyDict_New();
     if (self == NULL) {
         return NULL;
     }

_______________________________________________
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