Skip to content

Commit d0919f0

Browse files
authored
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.
1 parent b617993 commit d0919f0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Python/hashtable.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ _Py_hashtable_new_full(size_t key_size, size_t data_size,
149149
_Py_hashtable_allocator_t alloc;
150150

151151
if (allocator == NULL) {
152-
alloc.malloc = PyMem_RawMalloc;
153-
alloc.free = PyMem_RawFree;
152+
alloc.malloc = PyMem_Malloc;
153+
alloc.free = PyMem_Free;
154154
}
155-
else
155+
else {
156156
alloc = *allocator;
157+
}
157158

158159
ht = (_Py_hashtable_t *)alloc.malloc(sizeof(_Py_hashtable_t));
159160
if (ht == NULL)

0 commit comments

Comments
 (0)