Add an Option type and get rid of ENONE #19

Merged
apio merged 5 commits from optionals-and-empty-errors into restart 2022-12-08 15:13:24 +00:00
Showing only changes of commit da104c87cb - Show all commits

View File

@ -94,14 +94,14 @@ static usize get_fair_offset_to_split_at(HeapBlock* block, usize min)
return available + block->req_size;
}
static Result<HeapBlock*> split(HeapBlock* block, usize size)
static Option<HeapBlock*> split(HeapBlock* block, usize size)
{
const usize available = space_available(block); // How much space can we steal from this block?
const usize old_size =
block->full_size; // Save the old value of this variable since we are going to use it after modifying it
if (available < (size + sizeof(HeapBlock)))
return err(ENONE); // This block hasn't got enough free space to hold the requested size.
return {}; // This block hasn't got enough free space to hold the requested size.
const usize offset = get_fair_offset_to_split_at(block, size + sizeof(HeapBlock));
block->full_size = offset; // shrink the old block to fit this offset