specialize mi_mallocn for count=1

This commit is contained in:
daan 2020-01-16 14:12:37 -08:00
parent 8d8f355ed0
commit 4e91eab8fc

View File

@ -443,7 +443,12 @@ mi_decl_allocator void* mi_calloc(size_t count, size_t size) mi_attr_noexcept {
// Uninitialized `calloc` // Uninitialized `calloc`
extern mi_decl_allocator void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept { extern mi_decl_allocator void* mi_heap_mallocn(mi_heap_t* heap, size_t count, size_t size) mi_attr_noexcept {
size_t total; size_t total;
if (mi_mul_overflow(count,size,&total)) return NULL; if (count==1) {
total = size;
}
else if (mi_mul_overflow(count, size, &total)) {
return NULL;
}
return mi_heap_malloc(heap, total); return mi_heap_malloc(heap, total);
} }