Commit 57c13b66 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

core: remove try_alloc in block_allocator

parent 426d8a70
......@@ -598,30 +598,27 @@ public:
}
}
std::pair<bool, T*> try_alloc() noexcept
{
if (free_head == nullptr && max_size >= capacity)
return { false, nullptr };
return { true, alloc() };
}
T* alloc() noexcept
{
++size;
block* new_block = nullptr;
if (free_head != nullptr) {
new_block = free_head;
free_head = free_head->next;
} else {
assert(max_size < capacity);
irt_assert(max_size < capacity);
new_block = reinterpret_cast<block*>(&blocks[max_size++]);
}
++size;
return reinterpret_cast<T*>(new_block);
}
bool can_alloc() noexcept
{
return free_head != nullptr || max_size < capacity;
}
void free(T* n) noexcept
{
assert(n);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment