@@ -729,9 +729,7 @@ impl IntEncodedWithFixedSize {
729729impl serialize:: Encodable < Encoder > for IntEncodedWithFixedSize {
730730 fn encode ( & self , e : & mut Encoder ) -> EncodeResult {
731731 let start_pos = e. position ( ) ;
732- for i in 0 ..IntEncodedWithFixedSize :: ENCODED_SIZE {
733- ( ( self . 0 >> ( i * 8 ) ) as u8 ) . encode ( e) ?;
734- }
732+ e. emit_raw_bytes ( & self . 0 . to_le_bytes ( ) ) ;
735733 let end_pos = e. position ( ) ;
736734 assert_eq ! ( ( end_pos - start_pos) , IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
737735 Ok ( ( ) )
@@ -741,9 +739,7 @@ impl serialize::Encodable<Encoder> for IntEncodedWithFixedSize {
741739impl serialize:: Encodable < FileEncoder > for IntEncodedWithFixedSize {
742740 fn encode ( & self , e : & mut FileEncoder ) -> FileEncodeResult {
743741 let start_pos = e. position ( ) ;
744- for i in 0 ..IntEncodedWithFixedSize :: ENCODED_SIZE {
745- ( ( self . 0 >> ( i * 8 ) ) as u8 ) . encode ( e) ?;
746- }
742+ e. emit_raw_bytes ( & self . 0 . to_le_bytes ( ) ) ?;
747743 let end_pos = e. position ( ) ;
748744 assert_eq ! ( ( end_pos - start_pos) , IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
749745 Ok ( ( ) )
@@ -752,17 +748,13 @@ impl serialize::Encodable<FileEncoder> for IntEncodedWithFixedSize {
752748
753749impl < ' a > serialize:: Decodable < Decoder < ' a > > for IntEncodedWithFixedSize {
754750 fn decode ( decoder : & mut Decoder < ' a > ) -> Result < IntEncodedWithFixedSize , String > {
755- let mut value : u64 = 0 ;
751+ let mut bytes = MaybeUninit :: uninit_array ( ) ;
756752 let start_pos = decoder. position ( ) ;
757-
758- for i in 0 ..IntEncodedWithFixedSize :: ENCODED_SIZE {
759- let byte: u8 = serialize:: Decodable :: decode ( decoder) ?;
760- value |= ( byte as u64 ) << ( i * 8 ) ;
761- }
762-
753+ decoder. read_raw_bytes ( & mut bytes) ?;
763754 let end_pos = decoder. position ( ) ;
764755 assert_eq ! ( ( end_pos - start_pos) , IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
765756
757+ let value = u64:: from_le_bytes ( unsafe { MaybeUninit :: array_assume_init ( bytes) } ) ;
766758 Ok ( IntEncodedWithFixedSize ( value) )
767759 }
768760}
0 commit comments