File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -52,11 +52,14 @@ impl Chunk {
52
52
pub struct ChunkState ( u8 ) ;
53
53
54
54
impl ChunkState {
55
+ const ALLOC_BIT_MASK : u8 = 0x80 ;
56
+ const SPACE_INDEX_MASK : u8 = 0x0F ;
57
+
55
58
/// Create a new ChunkState that represents being allocated in the given space
56
59
pub fn allocated ( space_index : usize ) -> ChunkState {
57
60
debug_assert ! ( space_index < crate :: util:: heap:: layout:: heap_parameters:: MAX_SPACES ) ;
58
61
let mut encode = space_index as u8 ;
59
- encode |= 0x80 ;
62
+ encode |= Self :: ALLOC_BIT_MASK ;
60
63
ChunkState ( encode)
61
64
}
62
65
/// Create a new ChunkState that represents being free in the given space
@@ -66,16 +69,15 @@ impl ChunkState {
66
69
}
67
70
/// Is the chunk free?
68
71
pub fn is_free ( & self ) -> bool {
69
- self . 0 & 0x80 == 0
72
+ self . 0 & Self :: ALLOC_BIT_MASK == 0
70
73
}
71
74
/// Is the chunk allocated?
72
75
pub fn is_allocated ( & self ) -> bool {
73
76
!self . is_free ( )
74
77
}
75
78
/// Get the space index of the chunk
76
79
pub fn get_space_index ( & self ) -> usize {
77
- debug_assert ! ( self . is_allocated( ) ) ;
78
- let index = ( self . 0 & 0x0F ) as usize ;
80
+ let index = ( self . 0 & Self :: SPACE_INDEX_MASK ) as usize ;
79
81
debug_assert ! ( index < crate :: util:: heap:: layout:: heap_parameters:: MAX_SPACES ) ;
80
82
index
81
83
}
You can’t perform that action at this time.
0 commit comments