@@ -283,7 +283,7 @@ extra_only! {
283
283
#[ repr( C ) ]
284
284
struct CellHeader {
285
285
next_cell_raw : ptr:: NonNull < CellHeader > ,
286
- prev_cell : * mut CellHeader ,
286
+ prev_cell_raw : * mut CellHeader ,
287
287
}
288
288
289
289
#[ repr( C ) ]
@@ -415,10 +415,10 @@ impl CellHeader {
415
415
}
416
416
417
417
fn prev_cell ( & self ) -> Option < * mut CellHeader > {
418
- if self . prev_cell . is_null ( ) {
418
+ if self . prev_cell_raw . is_null ( ) {
419
419
None
420
420
} else {
421
- Some ( self . prev_cell )
421
+ Some ( self . prev_cell_raw )
422
422
}
423
423
}
424
424
@@ -460,7 +460,7 @@ impl FreeCell {
460
460
// true:
461
461
//
462
462
// * `FreeCell::next_free_raw` (and'd with the mask) is not null.
463
- // * `FreeCell::next_free_raw` is the adjacent `CellHeader::prev_cell `.
463
+ // * `FreeCell::next_free_raw` is the adjacent `CellHeader::prev_cell_raw `.
464
464
//
465
465
// Therefore, this free cell can be merged into a single, larger, contiguous
466
466
// free cell with its previous neighbor, which is also the next cell in the
@@ -505,7 +505,7 @@ impl FreeCell {
505
505
FreeCell {
506
506
header : CellHeader {
507
507
next_cell_raw : next_cell,
508
- prev_cell,
508
+ prev_cell_raw : prev_cell,
509
509
} ,
510
510
next_free_raw : next_free,
511
511
} ,
@@ -575,7 +575,7 @@ impl FreeCell {
575
575
576
576
if let Some ( next) = self . header . next_cell ( ) {
577
577
unsafe {
578
- ( * next) . prev_cell = & mut remainder. header ;
578
+ ( * next) . prev_cell_raw = & mut remainder. header ;
579
579
}
580
580
}
581
581
self . header . next_cell_raw =
@@ -676,7 +676,7 @@ extra_only! {
676
676
if let Some ( cell_ref) = cell. as_ref( ) {
677
677
assert!( cell_ref. size( ) >= size_of:: <usize >( ) ) ;
678
678
679
- if let Some ( prev) = cell_ref. prev_cell. as_ref( ) {
679
+ if let Some ( prev) = cell_ref. prev_cell( ) . and_then ( |p| p . as_ref( ) ) {
680
680
assert!( prev. size( ) >= size_of:: <usize >( ) ) ;
681
681
assert!( !prev. next_cell_is_invalid( ) ) ;
682
682
assert_eq!( prev. next_cell_unchecked( ) , cell, "next(prev(cell)) == cell" ) ;
@@ -686,7 +686,7 @@ extra_only! {
686
686
assert!( !next. is_null( ) ) ;
687
687
let next = & * next;
688
688
assert!( next. size( ) >= size_of:: <usize >( ) ) ;
689
- assert_eq!( next. prev_cell , cell, "prev(next(cell)) == cell" ) ;
689
+ assert_eq!( next. prev_cell_raw , cell, "prev(next(cell)) == cell" ) ;
690
690
}
691
691
692
692
if let Some ( free) = cell_ref. as_free_cell( ) {
@@ -844,27 +844,29 @@ where
844
844
845
845
let mut current_free = & mut * current_free;
846
846
847
- if policy. should_merge_adjacent_free_cells ( ) {
848
- // Now check if this cell can merge with the next cell in the free
849
- // list. We do this after the initial allocation attempt so that we
850
- // don't merge, only to immediately split the cell again right
851
- // afterwards.
852
- while current_free. next_free_can_merge ( ) {
853
- let prev_adjacent = current_free. header . prev_cell as * mut FreeCell ;
854
- extra_assert_eq ! ( prev_adjacent, current_free. next_free( ) ) ;
855
- let prev_adjacent = & mut * prev_adjacent;
856
-
857
- ( * prev_adjacent) . header . next_cell_raw = current_free. header . next_cell_raw ;
858
- if let Some ( next) = current_free. header . next_cell ( ) {
859
- ( * next) . prev_cell = & mut prev_adjacent. header ;
860
- }
847
+ // Now check if this cell can merge with the next cell in the free
848
+ // list.
849
+ //
850
+ // We don't re-check `policy.should_merge_adjacent_free_cells()` because
851
+ // the `NEXT_FREE_CELL_CAN_MERGE` bit only gets set after checking with
852
+ // the policy.
853
+ while current_free. next_free_can_merge ( ) {
854
+ extra_assert ! ( policy. should_merge_adjacent_free_cells( ) ) ;
855
+
856
+ let prev_adjacent = current_free. header . prev_cell_raw as * mut FreeCell ;
857
+ extra_assert_eq ! ( prev_adjacent, current_free. next_free( ) ) ;
858
+ let prev_adjacent = & mut * prev_adjacent;
859
+
860
+ ( * prev_adjacent) . header . next_cell_raw = current_free. header . next_cell_raw ;
861
+ if let Some ( next) = current_free. header . next_cell ( ) {
862
+ ( * next) . prev_cell_raw = & mut prev_adjacent. header ;
863
+ }
861
864
862
- * previous_free = prev_adjacent;
863
- current_free = prev_adjacent;
865
+ * previous_free = prev_adjacent;
866
+ current_free = prev_adjacent;
864
867
865
- write_free_pattern ( current_free, policy) ;
866
- assert_local_cell_invariants ( & mut current_free. header ) ;
867
- }
868
+ write_free_pattern ( current_free, policy) ;
869
+ assert_local_cell_invariants ( & mut current_free. header ) ;
868
870
}
869
871
870
872
if let Some ( result) = f ( previous_free, current_free) {
@@ -1055,7 +1057,7 @@ unsafe impl<'a> Alloc for &'a WeeAlloc {
1055
1057
{
1056
1058
prev. header . next_cell_raw = free. header . next_cell_raw ;
1057
1059
if let Some ( next) = free. header . next_cell ( ) {
1058
- ( * next) . prev_cell = & mut prev. header ;
1060
+ ( * next) . prev_cell_raw = & mut prev. header ;
1059
1061
}
1060
1062
1061
1063
write_free_pattern ( prev, policy) ;
0 commit comments