Skip to content

Commit

Permalink
bpo-33234: Simplify list_preallocate_exact() (pythonGH-11220)
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-sigurd authored and pablogsal committed Dec 29, 2018
1 parent d51324a commit 0e5f771
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,15 @@ static int
list_preallocate_exact(PyListObject *self, Py_ssize_t size)
{
assert(self->ob_item == NULL);
assert(size > 0);

PyObject **items;
size_t allocated;

allocated = (size_t)size;
if (allocated > (size_t)PY_SSIZE_T_MAX / sizeof(PyObject *)) {
PyErr_NoMemory();
return -1;
}

if (size == 0) {
allocated = 0;
}
items = (PyObject **)PyMem_New(PyObject*, allocated);
PyObject **items = PyMem_New(PyObject*, size);
if (items == NULL) {
PyErr_NoMemory();
return -1;
}
self->ob_item = items;
self->allocated = allocated;
self->allocated = size;
return 0;
}

Expand Down

0 comments on commit 0e5f771

Please sign in to comment.