]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33234: Simplify list_preallocate_exact() (GH-11220)
authorSergey Fedoseev <fedoseev.sergey@gmail.com>
Sat, 29 Dec 2018 22:31:36 +0000 (03:31 +0500)
committerPablo Galindo <Pablogsal@gmail.com>
Sat, 29 Dec 2018 22:31:36 +0000 (22:31 +0000)
Objects/listobject.c

index b1f2b59db0a72f34873b81d1a9f1a3d3315be268..17c37ba9756073dd8ee95808024dc972cdfc120c 100644 (file)
@@ -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;
 }