[kutil] Calculate block-size order with clz
Previously we were using a less efficient loop method of finding the appropriate block size order, now we use __builtin_clz, which should use the CPU's clz instruction if it's available.
This commit is contained in:
@@ -74,9 +74,10 @@ heap_allocator::allocate(size_t length)
|
||||
{
|
||||
size_t total = length + sizeof(mem_header);
|
||||
|
||||
unsigned order = min_order;
|
||||
while (total > (1 << order)) order++;
|
||||
if (length == 0)
|
||||
return nullptr;
|
||||
|
||||
unsigned order = 64 - __builtin_clz(length);
|
||||
kassert(order <= max_order, "Tried to allocate a block bigger than max_order");
|
||||
if (order > max_order)
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user