Heap: Return Option in split()
This commit is contained in:
parent
b6173e2b67
commit
da104c87cb
@ -94,14 +94,14 @@ static usize get_fair_offset_to_split_at(HeapBlock* block, usize min)
|
|||||||
return available + block->req_size;
|
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 available = space_available(block); // How much space can we steal from this block?
|
||||||
const usize old_size =
|
const usize old_size =
|
||||||
block->full_size; // Save the old value of this variable since we are going to use it after modifying it
|
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)))
|
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));
|
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
|
block->full_size = offset; // shrink the old block to fit this offset
|
||||||
|
Loading…
Reference in New Issue
Block a user