File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -688,26 +688,28 @@ pub mod checksum {
688
688
// For each 32-byte chunk...
689
689
const CHUNK_SIZE : usize = 32 ;
690
690
while data. len ( ) >= CHUNK_SIZE {
691
- let mut d = & data[ ..CHUNK_SIZE ] ;
691
+ let chunk = & data[ ..CHUNK_SIZE ] ;
692
+ let mut i = 0 ;
692
693
// ... take by 2 bytes and sum them.
693
- while d . len ( ) >= 2 {
694
- accum += NetworkEndian :: read_u16 ( d ) as u32 ;
695
- d = & d [ 2 .. ] ;
694
+ while i + 1 < CHUNK_SIZE {
695
+ accum += u16 :: from_be_bytes ( [ chunk [ i ] , chunk [ i + 1 ] ] ) as u32 ;
696
+ i += 2 ;
696
697
}
697
698
698
699
data = & data[ CHUNK_SIZE ..] ;
699
700
}
700
701
701
702
// Sum the rest that does not fit the last 32-byte chunk,
702
703
// taking by 2 bytes.
703
- while data. len ( ) >= 2 {
704
- accum += NetworkEndian :: read_u16 ( data) as u32 ;
705
- data = & data[ 2 ..] ;
704
+ let mut i = 0 ;
705
+ while i + 1 < data. len ( ) {
706
+ accum += u16:: from_be_bytes ( [ data[ i] , data[ i + 1 ] ] ) as u32 ;
707
+ i += 2 ;
706
708
}
707
709
708
710
// Add the last remaining odd byte, if any.
709
- if let Some ( & value ) = data. first ( ) {
710
- accum += ( value as u32 ) << 8 ;
711
+ if i < data. len ( ) {
712
+ accum += ( data [ i ] as u32 ) << 8 ;
711
713
}
712
714
713
715
propagate_carries ( accum)
You can’t perform that action at this time.
0 commit comments