diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2018-12-29 22:31:36 (GMT) |
---|---|---|
committer | Pablo Galindo <Pablogsal@gmail.com> | 2018-12-29 22:31:36 (GMT) |
commit | 0e5f771f38138714415f665651de7e674fcebc38 (patch) | |
tree | 556a1a26360389f0f18fb87bad407e717ea37671 /Objects/listobject.c | |
parent | d51324a2f5d172665f8824b25456c9822797fc84 (diff) | |
download | cpython-0e5f771f38138714415f665651de7e674fcebc38.zip cpython-0e5f771f38138714415f665651de7e674fcebc38.tar.gz cpython-0e5f771f38138714415f665651de7e674fcebc38.tar.bz2 |
bpo-33234: Simplify list_preallocate_exact() (GH-11220)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index b1f2b59..17c37ba 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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; } |