Skip to content

Commit 161c0f3

Browse files
committed
Run rustfmt
1 parent 7195f85 commit 161c0f3

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

src/hole.rs

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -205,80 +205,80 @@ fn allocate_first_fit(previous: &mut Hole, size: usize, align: usize) -> Option<
205205
/// find the correct place (the list is sorted by address).
206206
fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
207207
loop {
208-
assert!(size >= HoleList::min_size());
209-
210-
let hole_addr = if hole.size == 0 {
211-
// It's the dummy hole, which is the head of the HoleList. It's somewhere on the stack,
212-
// so it's address is not the address of the hole. We set the addr to 0 as it's always
213-
// the first hole.
214-
0
215-
} else {
216-
// tt's a real hole in memory and its address is the address of the hole
217-
hole as *mut _ as usize
218-
};
219-
220-
// Each freed block must be handled by the previous hole in memory. Thus the freed
221-
// address must be always behind the current hole.
222-
assert!(hole_addr + hole.size <= addr);
223-
224-
// get information about the next block
225-
let next_hole_info = hole.next.as_ref().map(|next| unsafe { next.get().info() });
226-
227-
match next_hole_info {
228-
Some(next) if hole_addr + hole.size == addr && addr + size == next.addr => {
229-
// block fills the gap between this hole and the next hole
230-
// before: ___XXX____YYYYY____ where X is this hole and Y the next hole
231-
// after: ___XXXFFFFYYYYY____ where F is the freed block
232-
233-
hole.size += size + next.size; // merge the F and Y blocks to this X block
234-
hole.next = hole.next_unwrap().next.take(); // remove the Y block
235-
}
236-
Some(_) if hole_addr + hole.size == addr => {
237-
// block is right behind this hole but there is used memory after it
238-
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
239-
// after: ___XXXFFFF__YYYYY____ where F is the freed block
208+
assert!(size >= HoleList::min_size());
209+
210+
let hole_addr = if hole.size == 0 {
211+
// It's the dummy hole, which is the head of the HoleList. It's somewhere on the stack,
212+
// so it's address is not the address of the hole. We set the addr to 0 as it's always
213+
// the first hole.
214+
0
215+
} else {
216+
// tt's a real hole in memory and its address is the address of the hole
217+
hole as *mut _ as usize
218+
};
219+
220+
// Each freed block must be handled by the previous hole in memory. Thus the freed
221+
// address must be always behind the current hole.
222+
assert!(hole_addr + hole.size <= addr);
223+
224+
// get information about the next block
225+
let next_hole_info = hole.next.as_ref().map(|next| unsafe { next.get().info() });
226+
227+
match next_hole_info {
228+
Some(next) if hole_addr + hole.size == addr && addr + size == next.addr => {
229+
// block fills the gap between this hole and the next hole
230+
// before: ___XXX____YYYYY____ where X is this hole and Y the next hole
231+
// after: ___XXXFFFFYYYYY____ where F is the freed block
232+
233+
hole.size += size + next.size; // merge the F and Y blocks to this X block
234+
hole.next = hole.next_unwrap().next.take(); // remove the Y block
235+
}
236+
Some(_) if hole_addr + hole.size == addr => {
237+
// block is right behind this hole but there is used memory after it
238+
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
239+
// after: ___XXXFFFF__YYYYY____ where F is the freed block
240240

241-
hole.size += size; // merge the F block to this X block
242-
}
243-
Some(next) if addr + size == next.addr => {
244-
// block is right before the next hole but there is used memory before it
245-
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
246-
// after: ___XXX__FFFFYYYYY____ where F is the freed block
247-
248-
hole.next = hole.next_unwrap().next.take(); // remove the Y block
249-
size += next.size; // free the merged F/Y block in next iteration
250-
continue;
251-
}
252-
Some(next) if next.addr <= addr => {
253-
// block is behind the next hole, so we delegate it to the next hole
254-
// before: ___XXX__YYYYY________ where X is this hole and Y the next hole
255-
// after: ___XXX__YYYYY__FFFF__ where F is the freed block
241+
hole.size += size; // merge the F block to this X block
242+
}
243+
Some(next) if addr + size == next.addr => {
244+
// block is right before the next hole but there is used memory before it
245+
// before: ___XXX______YYYYY____ where X is this hole and Y the next hole
246+
// after: ___XXX__FFFFYYYYY____ where F is the freed block
247+
248+
hole.next = hole.next_unwrap().next.take(); // remove the Y block
249+
size += next.size; // free the merged F/Y block in next iteration
250+
continue;
251+
}
252+
Some(next) if next.addr <= addr => {
253+
// block is behind the next hole, so we delegate it to the next hole
254+
// before: ___XXX__YYYYY________ where X is this hole and Y the next hole
255+
// after: ___XXX__YYYYY__FFFF__ where F is the freed block
256256

257-
hole = move_helper(hole).next_unwrap(); // start next iteration at next hole
258-
continue;
259-
}
260-
_ => {
261-
// block is between this and the next hole
262-
// before: ___XXX________YYYYY_ where X is this hole and Y the next hole
263-
// after: ___XXX__FFFF__YYYYY_ where F is the freed block
264-
265-
// or: this is the last hole
266-
// before: ___XXX_________ where X is this hole
267-
// after: ___XXX__FFFF___ where F is the freed block
268-
269-
let new_hole = Hole {
270-
size: size,
271-
next: hole.next.take(), // the reference to the Y block (if it exists)
272-
};
273-
// write the new hole to the freed memory
274-
let ptr = addr as *mut Hole;
275-
mem::forget(mem::replace(unsafe { &mut *ptr }, new_hole));
276-
// add the F block as the next block of the X block
277-
hole.next = Some(unsafe { Unique::new(ptr) });
257+
hole = move_helper(hole).next_unwrap(); // start next iteration at next hole
258+
continue;
259+
}
260+
_ => {
261+
// block is between this and the next hole
262+
// before: ___XXX________YYYYY_ where X is this hole and Y the next hole
263+
// after: ___XXX__FFFF__YYYYY_ where F is the freed block
264+
265+
// or: this is the last hole
266+
// before: ___XXX_________ where X is this hole
267+
// after: ___XXX__FFFF___ where F is the freed block
268+
269+
let new_hole = Hole {
270+
size: size,
271+
next: hole.next.take(), // the reference to the Y block (if it exists)
272+
};
273+
// write the new hole to the freed memory
274+
let ptr = addr as *mut Hole;
275+
mem::forget(mem::replace(unsafe { &mut *ptr }, new_hole));
276+
// add the F block as the next block of the X block
277+
hole.next = Some(unsafe { Unique::new(ptr) });
278+
}
278279
}
280+
break;
279281
}
280-
break;
281-
}
282282
}
283283

284284
/// Identity function to ease moving of references.

0 commit comments

Comments
 (0)