@@ -76,7 +76,7 @@ mod llff {
76
76
critical_section:: with ( |cs| self . heap . borrow ( cs) . borrow_mut ( ) . free ( ) )
77
77
}
78
78
79
- unsafe fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
79
+ fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
80
80
critical_section:: with ( |cs| {
81
81
self . heap
82
82
. borrow ( cs)
@@ -119,25 +119,15 @@ mod llff {
119
119
fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
120
120
match layout. size ( ) {
121
121
0 => Ok ( NonNull :: slice_from_raw_parts ( layout. dangling ( ) , 0 ) ) ,
122
- size => critical_section:: with ( |cs| {
123
- self . heap
124
- . borrow ( cs)
125
- . borrow_mut ( )
126
- . allocate_first_fit ( layout)
127
- . map ( |allocation| NonNull :: slice_from_raw_parts ( allocation, size) )
128
- . map_err ( |_| AllocError )
122
+ size => self . alloc ( layout) . map_or ( Err ( AllocError ) , |allocation| {
123
+ Ok ( NonNull :: slice_from_raw_parts ( allocation, size) )
129
124
} ) ,
130
125
}
131
126
}
132
127
133
128
unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) {
134
129
if layout. size ( ) != 0 {
135
- critical_section:: with ( |cs| {
136
- self . heap
137
- . borrow ( cs)
138
- . borrow_mut ( )
139
- . deallocate ( NonNull :: new_unchecked ( ptr. as_ptr ( ) ) , layout)
140
- } ) ;
130
+ self . dealloc ( ptr. as_ptr ( ) , layout) ;
141
131
}
142
132
}
143
133
}
@@ -201,7 +191,7 @@ mod tlsf {
201
191
} ) ;
202
192
}
203
193
204
- unsafe fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
194
+ fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
205
195
critical_section:: with ( |cs| self . heap . borrow ( cs) . borrow_mut ( ) . allocate ( layout) )
206
196
}
207
197
@@ -238,26 +228,15 @@ mod tlsf {
238
228
fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > {
239
229
match layout. size ( ) {
240
230
0 => Ok ( NonNull :: slice_from_raw_parts ( layout. dangling ( ) , 0 ) ) ,
241
- size => critical_section:: with ( |cs| {
242
- self . heap
243
- . borrow ( cs)
244
- . borrow_mut ( )
245
- . allocate ( layout)
246
- . map_or ( Err ( AllocError ) , |allocation| {
247
- Ok ( NonNull :: slice_from_raw_parts ( allocation, size) )
248
- } )
231
+ size => self . alloc ( layout) . map_or ( Err ( AllocError ) , |allocation| {
232
+ Ok ( NonNull :: slice_from_raw_parts ( allocation, size) )
249
233
} ) ,
250
234
}
251
235
}
252
236
253
237
unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) {
254
238
if layout. size ( ) != 0 {
255
- critical_section:: with ( |cs| {
256
- self . heap
257
- . borrow ( cs)
258
- . borrow_mut ( )
259
- . deallocate ( NonNull :: new_unchecked ( ptr. as_ptr ( ) ) , layout. align ( ) )
260
- } ) ;
239
+ self . dealloc ( ptr. as_ptr ( ) , layout) ;
261
240
}
262
241
}
263
242
}
0 commit comments