Fast allocation in a page: just pop from the free list. Fall back to generic allocation only if the list is empty. Note: in release mode the (inlined) routine is about 7 instructions with a single test.
| 30 | // Fall back to generic allocation only if the list is empty. |
| 31 | // Note: in release mode the (inlined) routine is about 7 instructions with a single test. |
| 32 | static mi_decl_forceinline void* mi_page_malloc_zero(mi_theap_t* theap, mi_page_t* page, size_t size, bool zero, size_t* usable) mi_attr_noexcept |
| 33 | { |
| 34 | if (page->block_size != 0) { // not the empty theap |
| 35 | mi_assert_internal(mi_page_block_size(page) >= size); |
| 36 | mi_assert_internal(_mi_is_aligned(mi_page_slice_start(page), MI_PAGE_ALIGN)); |
| 37 | mi_assert_internal(_mi_ptr_page(mi_page_start(page))==page); |
| 38 | } |
| 39 | |
| 40 | // check the free list |
| 41 | mi_block_t* const block = page->free; |
| 42 | if mi_unlikely(block == NULL) { |
| 43 | return _mi_malloc_generic(theap, size, (zero ? 1 : 0), usable); |
| 44 | } |
| 45 | mi_assert_internal(block != NULL && _mi_ptr_page(block) == page); |
| 46 | if (usable != NULL) { *usable = mi_page_usable_block_size(page); }; |
| 47 |
no test coverage detected