File tree 3 files changed +11
-19
lines changed
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);
53
53
macro_rules! impl_read_unsigned_leb128 {
54
54
( $fn_name: ident, $int_ty: ty) => {
55
55
#[ inline]
56
- pub fn $fn_name( slice: & [ u8 ] ) -> ( $int_ty, usize ) {
56
+ pub fn $fn_name( slice: & [ u8 ] , position : & mut usize ) -> $int_ty {
57
57
let mut result = 0 ;
58
58
let mut shift = 0 ;
59
- let mut position = 0 ;
60
59
loop {
61
- let byte = slice[ position] ;
62
- position += 1 ;
60
+ let byte = slice[ * position] ;
61
+ * position += 1 ;
63
62
if ( byte & 0x80 ) == 0 {
64
63
result |= ( byte as $int_ty) << shift;
65
- return ( result, position ) ;
64
+ return result;
66
65
} else {
67
66
result |= ( ( byte & 0x7F ) as $int_ty) << shift;
68
67
}
@@ -122,15 +121,14 @@ impl_write_signed_leb128!(write_isize_leb128, isize);
122
121
macro_rules! impl_read_signed_leb128 {
123
122
( $fn_name: ident, $int_ty: ty) => {
124
123
#[ inline]
125
- pub fn $fn_name( slice: & [ u8 ] ) -> ( $int_ty, usize ) {
124
+ pub fn $fn_name( slice: & [ u8 ] , position : & mut usize ) -> $int_ty {
126
125
let mut result = 0 ;
127
126
let mut shift = 0 ;
128
- let mut position = 0 ;
129
127
let mut byte;
130
128
131
129
loop {
132
- byte = slice[ position] ;
133
- position += 1 ;
130
+ byte = slice[ * position] ;
131
+ * position += 1 ;
134
132
result |= <$int_ty>:: from( byte & 0x7F ) << shift;
135
133
shift += 7 ;
136
134
@@ -144,7 +142,7 @@ macro_rules! impl_read_signed_leb128 {
144
142
result |= ( !0 << shift) ;
145
143
}
146
144
147
- ( result, position )
145
+ result
148
146
}
149
147
} ;
150
148
}
Original file line number Diff line number Diff line change @@ -559,11 +559,7 @@ impl<'a> Decoder<'a> {
559
559
}
560
560
561
561
macro_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) ) } } ;
567
563
}
568
564
569
565
impl < ' 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 {
30
30
31
31
let mut position = 0 ;
32
32
for & expected in & values {
33
- let ( actual, bytes_read ) = $read_fn_name( & stream[ position.. ] ) ;
33
+ let actual = $read_fn_name( & stream, & mut position) ;
34
34
assert_eq!( expected, actual) ;
35
- position += bytes_read;
36
35
}
37
36
assert_eq!( stream. len( ) , position) ;
38
37
}
@@ -77,9 +76,8 @@ macro_rules! impl_test_signed_leb128 {
77
76
78
77
let mut position = 0 ;
79
78
for & expected in & values {
80
- let ( actual, bytes_read ) = $read_fn_name( & stream[ position.. ] ) ;
79
+ let actual = $read_fn_name( & stream, & mut position) ;
81
80
assert_eq!( expected, actual) ;
82
- position += bytes_read;
83
81
}
84
82
assert_eq!( stream. len( ) , position) ;
85
83
}
You can’t perform that action at this time.
0 commit comments