Skip to content

Commit 46c9065

Browse files
committed
Increase the size of the last hole if the new hole aligns to it
1 parent 9a3bb89 commit 46c9065

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/hole.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,6 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
240240
hole.size += size + next.size; // merge the F and Y blocks to this X block
241241
hole.next = hole.next_unwrap().next.take(); // remove the Y block
242242
}
243-
Some(_) if hole_addr + hole.size == addr => {
244-
// block is right behind this hole but there is used memory after it
245-
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
246-
// after: ___XXXFFFF__YYYYY____ where F is the freed block
247-
248-
hole.size += size; // merge the F block to this X block
249-
}
250243
Some(next) if addr + size == next.addr => {
251244
// block is right before the next hole but there is used memory before it
252245
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
@@ -264,6 +257,17 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
264257
hole = move_helper(hole).next_unwrap(); // start next iteration at next hole
265258
continue;
266259
}
260+
_ if hole_addr + hole.size == addr => {
261+
// block is right behind this hole but there is used memory after it
262+
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
263+
// after: ___XXXFFFF__YYYYY____ where F is the freed block
264+
265+
// or: block is right behind this hole and this is the last hole
266+
// before: ___XXX_______________ where X is this hole and Y the next hole
267+
// after: ___XXXFFFF___________ where F is the freed block
268+
269+
hole.size += size; // merge the F block to this X block
270+
}
267271
_ => {
268272
// block is between this and the next hole
269273
// before: ___XXX________YYYYY_ where X is this hole and Y the next hole

0 commit comments

Comments
 (0)