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`.
| 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`. |
| 163 | static 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 | /* |
| 201 | static bool mi_page_queue_is_empty(mi_page_queue_t* queue) { |
no test coverage detected