@@ -21,25 +21,19 @@ pub(crate) struct Cursor {
21
21
impl Cursor {
22
22
fn next ( mut self ) -> Option < Self > {
23
23
unsafe {
24
- self . hole . as_mut ( ) . next . map ( |nhole| {
25
- Cursor {
26
- prev : self . hole ,
27
- hole : nhole,
28
- }
24
+ self . hole . as_mut ( ) . next . map ( |nhole| Cursor {
25
+ prev : self . hole ,
26
+ hole : nhole,
29
27
} )
30
28
}
31
29
}
32
30
33
31
fn current ( & self ) -> & Hole {
34
- unsafe {
35
- self . hole . as_ref ( )
36
- }
32
+ unsafe { self . hole . as_ref ( ) }
37
33
}
38
34
39
35
fn previous ( & self ) -> & Hole {
40
- unsafe {
41
- self . prev . as_ref ( )
42
- }
36
+ unsafe { self . prev . as_ref ( ) }
43
37
}
44
38
45
39
// On success, it returns the new allocation, and the linked list has been updated
@@ -128,8 +122,8 @@ impl Cursor {
128
122
Some ( HoleInfo {
129
123
addr : back_padding_start,
130
124
size : unsafe { hole_end. offset_from ( back_padding_start) }
131
- . try_into ( )
132
- . unwrap ( ) ,
125
+ . try_into ( )
126
+ . unwrap ( ) ,
133
127
} )
134
128
} else {
135
129
// No, it does not.
@@ -142,7 +136,9 @@ impl Cursor {
142
136
////////////////////////////////////////////////////////////////////////////
143
137
let Cursor { mut prev, mut hole } = self ;
144
138
// Remove the current location from the previous node
145
- unsafe { prev. as_mut ( ) . next = None ; }
139
+ unsafe {
140
+ prev. as_mut ( ) . next = None ;
141
+ }
146
142
// Take the next node out of our current node
147
143
let maybe_next_addr: Option < NonNull < Hole > > = unsafe { hole. as_mut ( ) . next . take ( ) } ;
148
144
@@ -153,8 +149,10 @@ impl Cursor {
153
149
( None , None ) => {
154
150
// No padding at all, how lucky! We still need to connect the PREVIOUS node
155
151
// to the NEXT node, if there was one
156
- unsafe { prev. as_mut ( ) . next = maybe_next_addr; }
157
- } ,
152
+ unsafe {
153
+ prev. as_mut ( ) . next = maybe_next_addr;
154
+ }
155
+ }
158
156
( None , Some ( singlepad) ) | ( Some ( singlepad) , None ) => unsafe {
159
157
// We have front padding OR back padding, but not both.
160
158
//
@@ -195,7 +193,7 @@ impl Cursor {
195
193
196
194
// Then connect the OLD previous to the NEW FRONT padding
197
195
prev. as_mut ( ) . next = Some ( NonNull :: new_unchecked ( frontpad_ptr) ) ;
198
- }
196
+ } ,
199
197
}
200
198
201
199
// Well that went swimmingly! Hand off the allocation, with surgery performed successfully!
@@ -324,10 +322,10 @@ impl HoleList {
324
322
match cursor. split_current ( aligned_layout) {
325
323
Ok ( ( ptr, _len) ) => {
326
324
return Ok ( ( NonNull :: new ( ptr) . ok_or ( ( ) ) ?, aligned_layout) ) ;
327
- } ,
325
+ }
328
326
Err ( curs) => {
329
327
cursor = curs. next ( ) . ok_or ( ( ) ) ?;
330
- } ,
328
+ }
331
329
}
332
330
}
333
331
}
@@ -358,10 +356,11 @@ impl HoleList {
358
356
/// Returns information about the first hole for test purposes.
359
357
#[ cfg( test) ]
360
358
pub fn first_hole ( & self ) -> Option < ( * const u8 , usize ) > {
361
- self . first
362
- . next
363
- . as_ref ( )
364
- . map ( |hole| ( hole. as_ptr ( ) as * mut u8 as * const u8 , unsafe { hole. as_ref ( ) . size } ) )
359
+ self . first . next . as_ref ( ) . map ( |hole| {
360
+ ( hole. as_ptr ( ) as * mut u8 as * const u8 , unsafe {
361
+ hole. as_ref ( ) . size
362
+ } )
363
+ } )
365
364
}
366
365
}
367
366
@@ -381,7 +380,7 @@ struct HoleInfo {
381
380
unsafe fn make_hole ( addr : * mut u8 , size : usize ) -> NonNull < Hole > {
382
381
let hole_addr = addr. cast :: < Hole > ( ) ;
383
382
debug_assert_eq ! ( addr as usize % align_of:: <Hole >( ) , 0 ) ;
384
- hole_addr. write ( Hole { size, next : None } ) ;
383
+ hole_addr. write ( Hole { size, next : None } ) ;
385
384
NonNull :: new_unchecked ( hole_addr)
386
385
}
387
386
@@ -475,7 +474,6 @@ impl Cursor {
475
474
hole = next;
476
475
}
477
476
}
478
-
479
477
}
480
478
}
481
479
@@ -508,7 +506,7 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
508
506
// Yup! It lives at the front of the list. Hooray! Attempt to merge
509
507
// it with just ONE next node, since it is at the front of the list
510
508
( cursor, 1 )
511
- } ,
509
+ }
512
510
Err ( mut cursor) => {
513
511
// Nope. It lives somewhere else. Advance the list until we find its home
514
512
while let Err ( ( ) ) = cursor. try_insert_after ( hole) {
@@ -519,7 +517,7 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
519
517
// the current node to the new node, then once more to combine the new node
520
518
// with the node after that.
521
519
( cursor, 2 )
522
- } ,
520
+ }
523
521
} ;
524
522
525
523
// We now need to merge up to two times to combine the current node with the next
@@ -529,14 +527,14 @@ fn deallocate(list: &mut HoleList, addr: *mut u8, size: usize) {
529
527
530
528
#[ cfg( test) ]
531
529
pub mod test {
530
+ use crate :: Heap ;
532
531
use core:: alloc:: Layout ;
533
532
use std:: mem:: MaybeUninit ;
534
533
use std:: prelude:: v1:: * ;
535
- use crate :: Heap ;
536
534
537
535
#[ repr( align( 128 ) ) ]
538
536
struct Chonk < const N : usize > {
539
- data : [ MaybeUninit < u8 > ; N ]
537
+ data : [ MaybeUninit < u8 > ; N ] ,
540
538
}
541
539
542
540
impl < const N : usize > Chonk < N > {
0 commit comments