]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40602: _Py_hashtable_new() uses PyMem_Malloc() (GH-20046)
authorVictor Stinner <vstinner@python.org>
Tue, 12 May 2020 01:07:40 +0000 (03:07 +0200)
committerGitHub <noreply@github.com>
Tue, 12 May 2020 01:07:40 +0000 (03:07 +0200)
_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.

Python/hashtable.c

index 22b84590105f9e6380e9a5436eb6ec86b8202e52..e9f02d8650e4f8f1f374d1a8aaff1b46ea11cdae 100644 (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)