@@ -894,6 +894,14 @@ pub enum InitChunk {
894894}
895895
896896impl InitChunk {
897+ #[ inline]
898+ pub fn is_init ( & self ) -> bool {
899+ match self {
900+ Self :: Init ( _) => true ,
901+ Self :: Uninit ( _) => false ,
902+ }
903+ }
904+
897905 #[ inline]
898906 pub fn range ( & self ) -> Range < Size > {
899907 match self {
@@ -1035,7 +1043,7 @@ impl InitMaskCompressed {
10351043
10361044/// Transferring the initialization mask to other allocations.
10371045impl < 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 .
10391047 ///
10401048 /// This is essentially a more space-efficient version of
10411049 /// `InitMask::range_as_init_chunks(...).collect::<Vec<_>>()`.
@@ -1053,10 +1061,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
10531061 // where each element toggles the state.
10541062
10551063 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 ( ) ;
10571068
10581069 // 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 {
10601071 let len = chunk. range ( ) . end . bytes ( ) - chunk. range ( ) . start . bytes ( ) ;
10611072 ranges. push ( len) ;
10621073 }
0 commit comments