Skip to content

Commit 1e406e6

Browse files
eendebakptclaude
andauthored
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 <noreply@anthropic.com>
1 parent af79f49 commit 1e406e6

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎Objects/dictobject.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5415,7 +5415,8 @@ dict_vectorcall(PyObject *type, PyObject * const*args,
54155415
return NULL;
54165416
}
54175417

5418-
PyObject *self = dict_new(_PyType_CAST(type), NULL, NULL);
5418+
assert(type == (PyObject *)&PyDict_Type);
5419+
PyObject *self = PyDict_New();
54195420
if (self == NULL) {
54205421
return NULL;
54215422
}

0 commit comments

Comments
 (0)