@@ -50,7 +50,6 @@ pub struct PageHeader {
50
50
mark_bits : BitVec ,
51
51
allocated_bits : BitVec ,
52
52
mark_fn : unsafe fn ( UntypedPointer , & mut MarkingTracer ) ,
53
- sweep_fn : unsafe fn ( & mut PageHeader ) ,
54
53
freelist : * mut ( ) ,
55
54
}
56
55
@@ -73,10 +72,6 @@ impl PageHeader {
73
72
( self . mark_fn ) ( ptr, tracer) ;
74
73
}
75
74
76
- pub unsafe fn sweep ( & mut self ) {
77
- ( self . sweep_fn ) ( self ) ;
78
- }
79
-
80
75
pub fn type_id ( & self ) -> usize {
81
76
self . mark_fn as usize
82
77
}
@@ -268,7 +263,6 @@ impl PageBox {
268
263
mark_bits : BitVec :: from_elem ( capacity, false ) ,
269
264
allocated_bits : BitVec :: from_elem ( capacity, false ) ,
270
265
mark_fn : mark_entry_point :: < T > ,
271
- sweep_fn : sweep_entry_point :: < T > ,
272
266
freelist : ptr:: null_mut ( ) ,
273
267
} ,
274
268
allocations : PhantomData ,
@@ -310,6 +304,8 @@ impl Drop for PageBox {
310
304
pub struct PageSet {
311
305
heap : * mut Heap ,
312
306
307
+ sweep_fn : unsafe fn ( & mut PageHeader ) ,
308
+
313
309
/// The collection of pages.
314
310
///
315
311
/// All pages in this collection have matching `.heap`, `.mark_fn`, and
@@ -326,25 +322,25 @@ impl PageSet {
326
322
/// # Safety
327
323
///
328
324
/// Safe as long as `heap` is a valid pointer.
329
- pub unsafe fn new ( heap : * mut Heap ) -> PageSet {
325
+ pub unsafe fn new < ' h , T : IntoHeapAllocation < ' h > > ( heap : * mut Heap ) -> PageSet {
330
326
PageSet {
331
327
heap,
328
+ sweep_fn : sweep_entry_point :: < T > ,
332
329
pages : vec ! [ ] ,
333
330
limit : None
334
331
}
335
332
}
336
333
337
334
/// Downcast to a typed PageSetRef.
338
335
///
339
- /// # Safety
336
+ /// # Panics
340
337
///
341
- /// The actual allocation type of this page set must be T .
342
- pub unsafe fn unchecked_downcast_mut < ' a , ' h , T > ( & ' a mut self ) -> PageSetRef < ' a , ' h , T >
338
+ /// If T is not the actual allocation type for this page set.
339
+ pub fn downcast_mut < ' a , ' h , T > ( & ' a mut self ) -> PageSetRef < ' a , ' h , T >
343
340
where
344
341
T : IntoHeapAllocation < ' h > + ' a
345
342
{
346
- // The assertion only covers the case where we have at least one page.
347
- assert ! ( self . pages. is_empty( ) || self . pages[ 0 ] . downcast_mut:: <T >( ) . is_some( ) ) ;
343
+ assert_eq ! ( self . sweep_fn as * const ( ) , sweep_entry_point:: <T > as * const ( ) ) ;
348
344
349
345
PageSetRef {
350
346
pages : self ,
@@ -371,7 +367,7 @@ impl PageSet {
371
367
/// Safe to call only as the final part of GC.
372
368
pub unsafe fn sweep ( & mut self ) {
373
369
for page in & mut self . pages {
374
- page . sweep ( ) ;
370
+ ( self . sweep_fn ) ( page ) ;
375
371
}
376
372
}
377
373
0 commit comments