10
10
use std:: {
11
11
alloc:: { AllocError , Allocator , Layout } ,
12
12
cell:: { Cell , UnsafeCell } ,
13
+ mem,
13
14
ptr:: { self , addr_of, NonNull } ,
14
15
thread:: { self , ThreadId } ,
15
- mem,
16
16
} ;
17
17
18
18
const BIN_SIZE : usize = 8 ;
@@ -33,7 +33,7 @@ impl MyBin {
33
33
}
34
34
// Cast the *entire* thing to a raw pointer to not restrict its provenance.
35
35
let bin = self as * const MyBin ;
36
- let base_ptr = UnsafeCell :: raw_get ( unsafe { addr_of ! ( ( * bin) . memory ) } ) . cast :: < usize > ( ) ;
36
+ let base_ptr = UnsafeCell :: raw_get ( unsafe { addr_of ! ( ( * bin) . memory) } ) . cast :: < usize > ( ) ;
37
37
let ptr = unsafe { NonNull :: new_unchecked ( base_ptr. add ( top) ) } ;
38
38
self . top . set ( top + 1 ) ;
39
39
Some ( ptr. cast ( ) )
@@ -64,22 +64,14 @@ impl MyAllocator {
64
64
MyAllocator {
65
65
thread_id,
66
66
bins : Box :: new (
67
- [ MyBin {
68
- top : Cell :: new ( 0 ) ,
69
- thread_id,
70
- memory : UnsafeCell :: default ( ) ,
71
- } ; 1 ] ,
67
+ [ MyBin { top : Cell :: new ( 0 ) , thread_id, memory : UnsafeCell :: default ( ) } ; 1 ] ,
72
68
) ,
73
69
}
74
70
}
75
71
76
72
// Pretends to be expensive finding a suitable bin for the layout.
77
73
fn find_bin ( & self , layout : Layout ) -> Option < & MyBin > {
78
- if layout == Layout :: new :: < usize > ( ) {
79
- Some ( & self . bins [ 0 ] )
80
- } else {
81
- None
82
- }
74
+ if layout == Layout :: new :: < usize > ( ) { Some ( & self . bins [ 0 ] ) } else { None }
83
75
}
84
76
}
85
77
0 commit comments