[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:
2020-07-30 19:54:25 -07:00
parent 73221dfe34
commit 94c1f0d3fc

View File

@@ -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;