Skip to content

Commit 27ad865

Browse files
committed
Rename the CellHeader::prev_cell field to prev_cell_raw
This matches `next_cell_raw`, and removes the ambiguity with the `prev_cell` method that does the null checking for us.
1 parent e40d57f commit 27ad865

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

wee_alloc/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ extra_only! {
283283
#[repr(C)]
284284
struct CellHeader {
285285
next_cell_raw: ptr::NonNull<CellHeader>,
286-
prev_cell: *mut CellHeader,
286+
prev_cell_raw: *mut CellHeader,
287287
}
288288

289289
#[repr(C)]
@@ -415,10 +415,10 @@ impl CellHeader {
415415
}
416416

417417
fn prev_cell(&self) -> Option<*mut CellHeader> {
418-
if self.prev_cell.is_null() {
418+
if self.prev_cell_raw.is_null() {
419419
None
420420
} else {
421-
Some(self.prev_cell)
421+
Some(self.prev_cell_raw)
422422
}
423423
}
424424

@@ -460,7 +460,7 @@ impl FreeCell {
460460
// true:
461461
//
462462
// * `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`.
464464
//
465465
// Therefore, this free cell can be merged into a single, larger, contiguous
466466
// free cell with its previous neighbor, which is also the next cell in the
@@ -505,7 +505,7 @@ impl FreeCell {
505505
FreeCell {
506506
header: CellHeader {
507507
next_cell_raw: next_cell,
508-
prev_cell,
508+
prev_cell_raw: prev_cell,
509509
},
510510
next_free_raw: next_free,
511511
},
@@ -575,7 +575,7 @@ impl FreeCell {
575575

576576
if let Some(next) = self.header.next_cell() {
577577
unsafe {
578-
(*next).prev_cell = &mut remainder.header;
578+
(*next).prev_cell_raw = &mut remainder.header;
579579
}
580580
}
581581
self.header.next_cell_raw =
@@ -676,7 +676,7 @@ extra_only! {
676676
if let Some(cell_ref) = cell.as_ref() {
677677
assert!(cell_ref.size() >= size_of::<usize>());
678678

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()) {
680680
assert!(prev.size() >= size_of::<usize>());
681681
assert!(!prev.next_cell_is_invalid());
682682
assert_eq!(prev.next_cell_unchecked(), cell, "next(prev(cell)) == cell");
@@ -686,7 +686,7 @@ extra_only! {
686686
assert!(!next.is_null());
687687
let next = &*next;
688688
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");
690690
}
691691

692692
if let Some(free) = cell_ref.as_free_cell() {
@@ -850,13 +850,13 @@ where
850850
// don't merge, only to immediately split the cell again right
851851
// afterwards.
852852
while current_free.next_free_can_merge() {
853-
let prev_adjacent = current_free.header.prev_cell as *mut FreeCell;
853+
let prev_adjacent = current_free.header.prev_cell_raw as *mut FreeCell;
854854
extra_assert_eq!(prev_adjacent, current_free.next_free());
855855
let prev_adjacent = &mut *prev_adjacent;
856856

857857
(*prev_adjacent).header.next_cell_raw = current_free.header.next_cell_raw;
858858
if let Some(next) = current_free.header.next_cell() {
859-
(*next).prev_cell = &mut prev_adjacent.header;
859+
(*next).prev_cell_raw = &mut prev_adjacent.header;
860860
}
861861

862862
*previous_free = prev_adjacent;
@@ -1055,7 +1055,7 @@ unsafe impl<'a> Alloc for &'a WeeAlloc {
10551055
{
10561056
prev.header.next_cell_raw = free.header.next_cell_raw;
10571057
if let Some(next) = free.header.next_cell() {
1058-
(*next).prev_cell = &mut prev.header;
1058+
(*next).prev_cell_raw = &mut prev.header;
10591059
}
10601060

10611061
write_free_pattern(prev, policy);

0 commit comments

Comments
 (0)