File tree Expand file tree Collapse file tree 3 files changed +11
-19
lines changed Expand file tree Collapse file tree 3 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -53,16 +53,15 @@ impl_write_unsigned_leb128!(write_usize_leb128, usize);
5353macro_rules! impl_read_unsigned_leb128 {
5454 ( $fn_name: ident, $int_ty: ty) => {
5555 #[ inline]
56- pub fn $fn_name( slice: & [ u8 ] ) -> ( $int_ty, usize ) {
56+ pub fn $fn_name( slice: & [ u8 ] , position : & mut usize ) -> $int_ty {
5757 let mut result = 0 ;
5858 let mut shift = 0 ;
59- let mut position = 0 ;
6059 loop {
61- let byte = slice[ position] ;
62- position += 1 ;
60+ let byte = slice[ * position] ;
61+ * position += 1 ;
6362 if ( byte & 0x80 ) == 0 {
6463 result |= ( byte as $int_ty) << shift;
65- return ( result, position ) ;
64+ return result;
6665 } else {
6766 result |= ( ( byte & 0x7F ) as $int_ty) << shift;
6867 }
@@ -122,15 +121,14 @@ impl_write_signed_leb128!(write_isize_leb128, isize);
122121macro_rules! impl_read_signed_leb128 {
123122 ( $fn_name: ident, $int_ty: ty) => {
124123 #[ inline]
125- pub fn $fn_name( slice: & [ u8 ] ) -> ( $int_ty, usize ) {
124+ pub fn $fn_name( slice: & [ u8 ] , position : & mut usize ) -> $int_ty {
126125 let mut result = 0 ;
127126 let mut shift = 0 ;
128- let mut position = 0 ;
129127 let mut byte;
130128
131129 loop {
132- byte = slice[ position] ;
133- position += 1 ;
130+ byte = slice[ * position] ;
131+ * position += 1 ;
134132 result |= <$int_ty>:: from( byte & 0x7F ) << shift;
135133 shift += 7 ;
136134
@@ -144,7 +142,7 @@ macro_rules! impl_read_signed_leb128 {
144142 result |= ( !0 << shift) ;
145143 }
146144
147- ( result, position )
145+ result
148146 }
149147 } ;
150148}
Original file line number Diff line number Diff line change @@ -559,11 +559,7 @@ impl<'a> Decoder<'a> {
559559}
560560
561561macro_rules! read_leb128 {
562- ( $dec: expr, $fun: ident) => { {
563- let ( value, bytes_read) = leb128:: $fun( & $dec. data[ $dec. position..] ) ;
564- $dec. position += bytes_read;
565- Ok ( value)
566- } } ;
562+ ( $dec: expr, $fun: ident) => { { Ok ( leb128:: $fun( $dec. data, & mut $dec. position) ) } } ;
567563}
568564
569565impl < ' a > serialize:: Decoder for Decoder < ' a > {
Original file line number Diff line number Diff line change @@ -30,9 +30,8 @@ macro_rules! impl_test_unsigned_leb128 {
3030
3131 let mut position = 0 ;
3232 for & expected in & values {
33- let ( actual, bytes_read ) = $read_fn_name( & stream[ position.. ] ) ;
33+ let actual = $read_fn_name( & stream, & mut position) ;
3434 assert_eq!( expected, actual) ;
35- position += bytes_read;
3635 }
3736 assert_eq!( stream. len( ) , position) ;
3837 }
@@ -77,9 +76,8 @@ macro_rules! impl_test_signed_leb128 {
7776
7877 let mut position = 0 ;
7978 for & expected in & values {
80- let ( actual, bytes_read ) = $read_fn_name( & stream[ position.. ] ) ;
79+ let actual = $read_fn_name( & stream, & mut position) ;
8180 assert_eq!( expected, actual) ;
82- position += bytes_read;
8381 }
8482 assert_eq!( stream. len( ) , position) ;
8583 }
You can’t perform that action at this time.
0 commit comments