mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[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);
|
size_t total = length + sizeof(mem_header);
|
||||||
|
|
||||||
unsigned order = min_order;
|
if (length == 0)
|
||||||
while (total > (1 << order)) order++;
|
return nullptr;
|
||||||
|
|
||||||
|
unsigned order = 64 - __builtin_clz(length);
|
||||||
kassert(order <= max_order, "Tried to allocate a block bigger than max_order");
|
kassert(order <= max_order, "Tried to allocate a block bigger than max_order");
|
||||||
if (order > max_order)
|
if (order > max_order)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user