Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Round up to the even number.
  • Loading branch information
serhiy-storchaka committed May 18, 2022
commit a6b1a798e67795a001bff775f8c71b7d9d5f98a1
14 changes: 5 additions & 9 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +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,
* there is no benefit of allocating space for the odd number of items,
* and there is no drawback of rounding it up.
/* 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.
*/
if (sizeof(PyObject*) > 4) {
size = (size + 1) & ~(size_t)1;
}
else {
size = (size + 3) & ~(size_t)3;
}
size = (size + 1) & ~(size_t)1;
PyObject **items = PyMem_New(PyObject*, size);
if (items == NULL) {
PyErr_NoMemory();
Expand Down