Skip to content

Commit 386d9d0

Browse files
authored
gh-160858: Use the list freelist in list() (gh-160859)
1 parent 2e1666f commit 386d9d0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎Objects/listobject.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,7 +3600,7 @@ static int
36003600
list___init___impl(PyListObject *self, PyObject *iterable)
36013601
/*[clinic end generated code: output=0f3c21379d01de48 input=b3f3fe7206af8f6b]*/
36023602
{
3603-
/* Verify list invariants established by PyType_GenericAlloc() */
3603+
/* Verify list invariants */
36043604
assert(0 <= Py_SIZE(self));
36053605
assert(Py_SIZE(self) <= self->allocated || self->allocated == -1);
36063606
assert(self->ob_item != NULL ||
@@ -3632,7 +3632,10 @@ list_vectorcall(PyObject *type, PyObject * const*args,
36323632
return NULL;
36333633
}
36343634

3635-
PyObject *list = PyType_GenericAlloc(_PyType_CAST(type), 0);
3635+
/* use PyList_New() to make exact lists from the freelist. */
3636+
PyObject *list = (type == (PyObject *)&PyList_Type
3637+
? PyList_New(0)
3638+
: PyType_GenericAlloc(_PyType_CAST(type), 0));
36363639
if (list == NULL) {
36373640
return NULL;
36383641
}

0 commit comments

Comments
 (0)