mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-92914: Round the allocated size for lists up to the even number (GH-92915)
This commit is contained in:
parent
96f65835f8
commit
8a6af5a346
3 changed files with 11 additions and 3 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue