Skip to content

Commit 0e5f771

Browse files
sir-sigurdpablogsal
authored andcommitted
bpo-33234: Simplify list_preallocate_exact() (GH-11220)
1 parent d51324a commit 0e5f771

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

Objects/listobject.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,15 @@ static int
8181
list_preallocate_exact(PyListObject *self, Py_ssize_t size)
8282
{
8383
assert(self->ob_item == NULL);
84+
assert(size > 0);
8485

85-
PyObject **items;
86-
size_t allocated;
87-
88-
allocated = (size_t)size;
89-
if (allocated > (size_t)PY_SSIZE_T_MAX / sizeof(PyObject *)) {
90-
PyErr_NoMemory();
91-
return -1;
92-
}
93-
94-
if (size == 0) {
95-
allocated = 0;
96-
}
97-
items = (PyObject **)PyMem_New(PyObject*, allocated);
86+
PyObject **items = PyMem_New(PyObject*, size);
9887
if (items == NULL) {
9988
PyErr_NoMemory();
10089
return -1;
10190
}
10291
self->ob_item = items;
103-
self->allocated = allocated;
92+
self->allocated = size;
10493
return 0;
10594
}
10695

0 commit comments

Comments
 (0)