diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-05-19 05:43:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 05:43:50 (GMT) |
commit | 8a6af5a34642f5564220eb50d72caada8f17fc78 (patch) | |
tree | 79595d9287532adcd7bb6c7a63950a0ca9e10dca /Objects/listobject.c | |
parent | 96f65835f8f66d058b444e0b4e436af45e2902f7 (diff) | |
download | cpython-8a6af5a34642f5564220eb50d72caada8f17fc78.zip cpython-8a6af5a34642f5564220eb50d72caada8f17fc78.tar.gz cpython-8a6af5a34642f5564220eb50d72caada8f17fc78.tar.bz2 |
gh-92914: Round the allocated size for lists up to the even number (GH-92915)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index b50623e..0a99ec9 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -94,6 +94,12 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size) assert(self->ob_item == NULL); assert(size > 0); + /* Since the Python memory allocator has granularity of 16 bytes on 64-bit + * platforms (8 on 32-bit), there is no benefit of allocating space for + * the odd number of items, and there is no drawback of rounding the + * allocated size up to the nearest even number. + */ + size = (size + 1) & ~(size_t)1; PyObject **items = PyMem_New(PyObject*, size); if (items == NULL) { PyErr_NoMemory(); |