@@ -43,8 +43,8 @@ impl HoleList {
43
43
/// Searches the list for a big enough hole. A hole is big enough if it can hold an allocation
44
44
/// of `size` bytes with the given `align`. If such a hole is found in the list, a block of the
45
45
/// required size is allocated from it. Then the start address of that block is returned.
46
- /// This function uses the “first fit” strategy, so it uses the first hole that is big enough.
47
- /// Thus the runtime is in O(n) but it should be reasonably fast for small allocations.
46
+ /// This function uses the “first fit” strategy, so it uses the first hole that is big
47
+ /// enough. Thus the runtime is in O(n) but it should be reasonably fast for small allocations.
48
48
pub fn allocate_first_fit ( & mut self , size : usize , align : usize ) -> Option < * mut u8 > {
49
49
assert ! ( size >= Self :: min_size( ) ) ;
50
50
@@ -136,10 +136,11 @@ fn split_hole(hole: HoleInfo, required_size: usize, required_align: usize) -> Op
136
136
} else {
137
137
// the required alignment causes some padding before the allocation
138
138
let aligned_addr = align_up ( hole. addr + HoleList :: min_size ( ) , required_align) ;
139
- ( aligned_addr, Some ( HoleInfo {
140
- addr : hole. addr ,
141
- size : aligned_addr - hole. addr ,
142
- } ) )
139
+ ( aligned_addr,
140
+ Some ( HoleInfo {
141
+ addr : hole. addr ,
142
+ size : aligned_addr - hole. addr ,
143
+ } ) )
143
144
} ;
144
145
145
146
let aligned_hole = {
@@ -181,13 +182,13 @@ fn split_hole(hole: HoleInfo, required_size: usize, required_align: usize) -> Op
181
182
/// enough if it can hold an allocation of `size` bytes with the given `align`. When a hole is used
182
183
/// for an allocation, there may be some needed padding before and/or after the allocation. This
183
184
/// padding is returned as part of the `Allocation`. The caller must take care of freeing it again.
184
- /// This function uses the “first fit” strategy, so it breaks as soon as a big enough hole is found
185
- /// (and returns it).
185
+ /// This function uses the “first fit” strategy, so it breaks as soon as a big enough hole is
186
+ /// found (and returns it).
186
187
fn allocate_first_fit ( mut previous : & mut Hole , size : usize , align : usize ) -> Option < Allocation > {
187
188
loop {
188
- let allocation: Option < Allocation > = previous. next . as_mut ( ) . and_then ( |current| {
189
- split_hole ( unsafe { current . get ( ) } . info ( ) , size , align )
190
- } ) ;
189
+ let allocation: Option < Allocation > = previous. next
190
+ . as_mut ( )
191
+ . and_then ( |current| split_hole ( unsafe { current . get ( ) } . info ( ) , size , align ) ) ;
191
192
match allocation {
192
193
Some ( allocation) => {
193
194
// hole is big enough, so remove it from the list by updating the previous pointer
@@ -251,7 +252,7 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
251
252
// after: ___XXX__FFFFYYYYY____ where F is the freed block
252
253
253
254
hole. next = hole. next_unwrap ( ) . next . take ( ) ; // remove the Y block
254
- size += next. size ; // free the merged F/Y block in next iteration
255
+ size += next. size ; // free the merged F/Y block in next iteration
255
256
continue ;
256
257
}
257
258
Some ( next) if next. addr <= addr => {
0 commit comments