mirror of https://github.com/python/cpython
bpo-33234: Simplify list_preallocate_exact() (GH-11220)
This commit is contained in:
parent
d51324a2f5
commit
0e5f771f38
|
@ -81,26 +81,15 @@ static int
|
||||||
list_preallocate_exact(PyListObject *self, Py_ssize_t size)
|
list_preallocate_exact(PyListObject *self, Py_ssize_t size)
|
||||||
{
|
{
|
||||||
assert(self->ob_item == NULL);
|
assert(self->ob_item == NULL);
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
PyObject **items;
|
PyObject **items = PyMem_New(PyObject*, size);
|
||||||
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);
|
|
||||||
if (items == NULL) {
|
if (items == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
self->ob_item = items;
|
self->ob_item = items;
|
||||||
self->allocated = allocated;
|
self->allocated = size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue