Jinoh Kang (@iamahuman) commented about dlls/ntdll/heap.c:
+ * 72, 80, 88, 96, 104, 112, 120, 128, + * ... + */ +static unsigned long get_free_list_block( size_t size ) { - if (index < HEAP_NB_SMALL_FREE_LISTS) return HEAP_MIN_BLOCK_SIZE + index * BLOCK_ALIGN; - return free_list_sizes[index - HEAP_NB_SMALL_FREE_LISTS]; + size_t bsize = size / BLOCK_ALIGN; + DWORD b; + unsigned long block, log, linear; + + if ( bsize > UINT_MAX ) + return NB_FREE_LISTS - 1; + + /* find the highest bit */ + if ( !BitScanReverse( &b, bsize ) || b < FREE_LIST_LINEAR_BITS ) How about shifting `bsize` right by `FREE_LIST_LINEAR_BITS` before passing it to `BitScanReverse`? That'll eliminate extra comparsion as well as subtraction in `b - FREE_LIST_LINEAR_BITS`.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/2622#note_29458