@@ -152,7 +152,6 @@ impl BitVec<'_> {
152152 if buf. is_empty ( ) {
153153 return Self :: default ( ) ;
154154 }
155-
156155 // The first byte of the serialized BitVec is used to indicate how many
157156 // of the bits in the left-most u64 block are *unoccupied*.
158157 // See [`BitVec::write`] implementation for how this is done.
@@ -161,25 +160,21 @@ impl BitVec<'_> {
161160 "Number of unoccupied bits should be <64, got {}" ,
162161 buf[ 0 ]
163162 ) ;
164-
165163 let num_bits = ( buf. len ( ) - 1 ) * 8 - buf[ 0 ] as usize ;
166164 buf = & buf[ 1 ..] ;
167-
168165 assert_eq ! (
169166 buf. len( ) % BYTES_PER_BLOCK ,
170167 0 ,
171168 "buffer should be a multiple of 8 bytes, got {}" ,
172169 buf. len( )
173170 ) ;
174-
175171 let blocks = unsafe {
176172 std:: mem:: transmute :: < & [ u8 ] , & [ u64 ] > ( std:: slice:: from_raw_parts (
177173 buf. as_ptr ( ) ,
178174 buf. len ( ) / BYTES_PER_BLOCK ,
179175 ) )
180176 } ;
181177 let blocks = Cow :: Borrowed ( blocks) ;
182-
183178 Self { num_bits, blocks }
184179 }
185180
@@ -188,18 +183,14 @@ impl BitVec<'_> {
188183 if self . is_empty ( ) {
189184 return Ok ( 0 ) ;
190185 }
191-
192186 // First serialize the number of unoccupied bits in the last block as one byte.
193187 let unoccupied_bits = 63 - ( ( self . num_bits - 1 ) % 64 ) as u8 ;
194188 writer. write_all ( & [ unoccupied_bits] ) ?;
195-
196189 let blocks = self . blocks . deref ( ) ;
197190 let block_bytes = unsafe {
198191 std:: slice:: from_raw_parts ( blocks. as_ptr ( ) as * const u8 , blocks. len ( ) * BYTES_PER_BLOCK )
199192 } ;
200-
201193 writer. write_all ( block_bytes) ?;
202-
203194 Ok ( block_bytes. len ( ) + 1 )
204195 }
205196}
0 commit comments