MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_heap_queue_first_update

Function mi_heap_queue_first_update

3rd/mimalloc-2.0.9/src/page-queue.c:163–198  ·  view source on GitHub ↗

The current small page array is for efficiency and for each small size (up to 256) it points directly to the page for that size without having to compute the bin. This means when the current free page queue is updated for a small bin, we need to update a range of entries in `_mi_page_small_free`.

Source from the content-addressed store, hash-verified

161// current free page queue is updated for a small bin, we need to update a
162// range of entries in `_mi_page_small_free`.
163static inline void mi_heap_queue_first_update(mi_heap_t* heap, const mi_page_queue_t* pq) {
164 mi_assert_internal(mi_heap_contains_queue(heap,pq));
165 size_t size = pq->block_size;
166 if (size > MI_SMALL_SIZE_MAX) return;
167
168 mi_page_t* page = pq->first;
169 if (pq->first == NULL) page = (mi_page_t*)&_mi_page_empty;
170
171 // find index in the right direct page array
172 size_t start;
173 size_t idx = _mi_wsize_from_size(size);
174 mi_page_t** pages_free = heap->pages_free_direct;
175
176 if (pages_free[idx] == page) return; // already set
177
178 // find start slot
179 if (idx<=1) {
180 start = 0;
181 }
182 else {
183 // find previous size; due to minimal alignment upto 3 previous bins may need to be skipped
184 uint8_t bin = mi_bin(size);
185 const mi_page_queue_t* prev = pq - 1;
186 while( bin == mi_bin(prev->block_size) && prev > &heap->pages[0]) {
187 prev--;
188 }
189 start = 1 + _mi_wsize_from_size(prev->block_size);
190 if (start > idx) start = idx;
191 }
192
193 // set size range to the right page
194 mi_assert(start <= idx);
195 for (size_t sz = start; sz <= idx; sz++) {
196 pages_free[sz] = page;
197 }
198}
199
200/*
201static bool mi_page_queue_is_empty(mi_page_queue_t* queue) {

Callers 4

mi_page_queue_removeFunction · 0.85
mi_page_queue_pushFunction · 0.85
_mi_page_queue_appendFunction · 0.85

Calls 3

mi_heap_contains_queueFunction · 0.85
mi_binFunction · 0.85
_mi_wsize_from_sizeFunction · 0.50

Tested by

no test coverage detected