Skip to content

Commit b7dc997

Browse files
committed
Increase the size of the last hole if the new hole aligns to it
1 parent ea8548d commit b7dc997

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/hole.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,21 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
271271

272272
// or: this is the last hole
273273
// before: ___XXX_________ where X is this hole
274-
// after: ___XXX__FFFF___ where F is the freed block
275-
276-
let new_hole = Hole {
277-
size: size,
278-
next: hole.next.take(), // the reference to the Y block (if it exists)
279-
};
280-
// write the new hole to the freed memory
281-
let ptr = addr as *mut Hole;
282-
mem::forget(mem::replace(unsafe { &mut *ptr }, new_hole));
283-
// add the F block as the next block of the X block
284-
hole.next = Some(unsafe { Unique::new(ptr) });
274+
if hole_addr + hole.size == addr {
275+
// after: ___XXXFFFF___ where F is the freed block
276+
hole.size += size;
277+
} else {
278+
// after: ___XXX__FFFF___ where F is the freed block
279+
let new_hole = Hole {
280+
size: size,
281+
next: hole.next.take(), // the reference to the Y block (if it exists)
282+
};
283+
// write the new hole to the freed memory
284+
let ptr = addr as *mut Hole;
285+
mem::forget(mem::replace(unsafe { &mut *ptr }, new_hole));
286+
// add the F block as the next block of the X block
287+
hole.next = Some(unsafe { Unique::new(ptr) });
288+
}
285289
}
286290
}
287291
break;

0 commit comments

Comments
 (0)