bpo-40602: _Py_hashtable_new() uses PyMem_Malloc() (GH-20046)

_Py_hashtable_new() now uses PyMem_Malloc/PyMem_Free allocator by
default, rather than PyMem_RawMalloc/PyMem_RawFree.

PyMem_Malloc is faster than PyMem_RawMalloc for memory blocks smaller
than or equal to 512 bytes.
This commit is contained in:
Victor Stinner 2020-05-12 03:07:40 +02:00 committed by GitHub
parent b617993b7c
commit d0919f0d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -149,11 +149,12 @@ _Py_hashtable_new_full(size_t key_size, size_t data_size,
_Py_hashtable_allocator_t alloc;
if (allocator == NULL) {
alloc.malloc = PyMem_RawMalloc;
alloc.free = PyMem_RawFree;
alloc.malloc = PyMem_Malloc;
alloc.free = PyMem_Free;
}
else
else {
alloc = *allocator;
}
ht = (_Py_hashtable_t *)alloc.malloc(sizeof(_Py_hashtable_t));
if (ht == NULL)