@@ -894,6 +894,14 @@ pub enum InitChunk {
894
894
}
895
895
896
896
impl InitChunk {
897
+ #[ inline]
898
+ pub fn is_init ( & self ) -> bool {
899
+ match self {
900
+ Self :: Init ( _) => true ,
901
+ Self :: Uninit ( _) => false ,
902
+ }
903
+ }
904
+
897
905
#[ inline]
898
906
pub fn range ( & self ) -> Range < Size > {
899
907
match self {
@@ -1035,7 +1043,7 @@ impl InitMaskCompressed {
1035
1043
1036
1044
/// Transferring the initialization mask to other allocations.
1037
1045
impl < Tag , Extra > Allocation < Tag , Extra > {
1038
- /// Creates a run-length encoding of the initialization mask.
1046
+ /// Creates a run-length encoding of the initialization mask; panics if range is empty .
1039
1047
///
1040
1048
/// This is essentially a more space-efficient version of
1041
1049
/// `InitMask::range_as_init_chunks(...).collect::<Vec<_>>()`.
@@ -1053,10 +1061,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
1053
1061
// where each element toggles the state.
1054
1062
1055
1063
let mut ranges = smallvec:: SmallVec :: < [ u64 ; 1 ] > :: new ( ) ;
1056
- let initial = self . init_mask . get ( range. start ) ;
1064
+
1065
+ let mut chunks = self . init_mask . range_as_init_chunks ( range. start , range. end ( ) ) . peekable ( ) ;
1066
+
1067
+ let initial = chunks. peek ( ) . expect ( "range should be nonempty" ) . is_init ( ) ;
1057
1068
1058
1069
// Here we rely on `range_as_init_chunks` to yield alternating init/uninit chunks.
1059
- for chunk in self . init_mask . range_as_init_chunks ( range . start , range . end ( ) ) {
1070
+ for chunk in chunks {
1060
1071
let len = chunk. range ( ) . end . bytes ( ) - chunk. range ( ) . start . bytes ( ) ;
1061
1072
ranges. push ( len) ;
1062
1073
}
0 commit comments