@@ -688,7 +688,8 @@ pub mod checksum {
688
688
// For each 32-byte chunk...
689
689
const CHUNK_SIZE : usize = 32 ;
690
690
const WORD_SIZE : usize = 2 ;
691
- for chunk in data. chunks_exact ( CHUNK_SIZE ) {
691
+ let mut chunks = data. chunks_exact ( CHUNK_SIZE ) ;
692
+ for chunk in & mut chunks {
692
693
// ... take by 2 bytes and sum them.
693
694
for pair in chunk. chunks_exact ( WORD_SIZE ) {
694
695
accum += u16:: from_be_bytes ( [ pair[ 0 ] , pair[ 1 ] ] ) as u32 ;
@@ -697,15 +698,15 @@ pub mod checksum {
697
698
698
699
// Sum the rest that does not fit the last 32-byte chunk,
699
700
// taking by 2 bytes.
700
- let remainder = data. chunks_exact ( CHUNK_SIZE ) . remainder ( ) ;
701
- for pair in remainder. chunks_exact ( WORD_SIZE ) {
701
+ let remainder = chunks. remainder ( ) ;
702
+ let mut word_pairs = remainder. chunks_exact ( WORD_SIZE ) ;
703
+ for pair in & mut word_pairs {
702
704
accum += u16:: from_be_bytes ( [ pair[ 0 ] , pair[ 1 ] ] ) as u32 ;
703
705
}
704
706
705
707
// Add the last remaining odd byte, if any.
706
- let last = remainder. chunks_exact ( WORD_SIZE ) . remainder ( ) ;
707
- if !last. is_empty ( ) {
708
- accum += ( last[ 0 ] as u32 ) << 8 ;
708
+ if let Some ( & byte) = word_pairs. remainder ( ) . first ( ) {
709
+ accum += ( byte as u32 ) << 8 ;
709
710
}
710
711
711
712
propagate_carries ( accum)
0 commit comments