@@ -44,13 +44,7 @@ pub trait Encoder {
4444 f ( self )
4545 }
4646
47- fn emit_enum_variant < F > (
48- & mut self ,
49- _v_name : & str ,
50- v_id : usize ,
51- _len : usize ,
52- f : F ,
53- ) -> Result < ( ) , Self :: Error >
47+ fn emit_enum_variant < F > ( & mut self , v_id : usize , f : F ) -> Result < ( ) , Self :: Error >
5448 where
5549 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
5650 {
@@ -65,47 +59,44 @@ pub trait Encoder {
6559 // optimization that would otherwise be necessary here, likely due to the
6660 // multiple levels of inlining and const-prop that are needed.
6761 #[ inline]
68- fn emit_fieldless_enum_variant < const ID : usize > (
69- & mut self ,
70- _v_name : & str ,
71- ) -> Result < ( ) , Self :: Error > {
62+ fn emit_fieldless_enum_variant < const ID : usize > ( & mut self ) -> Result < ( ) , Self :: Error > {
7263 self . emit_usize ( ID )
7364 }
7465
7566 #[ inline]
76- fn emit_enum_variant_arg < F > ( & mut self , _first : bool , f : F ) -> Result < ( ) , Self :: Error >
67+ fn emit_enum_variant_arg < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
7768 where
7869 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
7970 {
8071 f ( self )
8172 }
8273
8374 #[ inline]
84- fn emit_struct < F > ( & mut self , _no_fields : bool , f : F ) -> Result < ( ) , Self :: Error >
75+ fn emit_struct < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
8576 where
8677 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
8778 {
8879 f ( self )
8980 }
9081
9182 #[ inline]
92- fn emit_struct_field < F > ( & mut self , _f_name : & str , _first : bool , f : F ) -> Result < ( ) , Self :: Error >
83+ fn emit_struct_field < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
9384 where
9485 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
9586 {
9687 f ( self )
9788 }
9889
9990 #[ inline]
100- fn emit_tuple < F > ( & mut self , _len : usize , f : F ) -> Result < ( ) , Self :: Error >
91+ fn emit_tuple < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
10192 where
10293 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
10394 {
10495 f ( self )
10596 }
10697
10798 #[ inline]
108- fn emit_tuple_arg < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
99+ fn emit_tuple_arg < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
109100 where
110101 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
111102 {
@@ -122,14 +113,14 @@ pub trait Encoder {
122113
123114 #[ inline]
124115 fn emit_option_none ( & mut self ) -> Result < ( ) , Self :: Error > {
125- self . emit_enum_variant ( "None" , 0 , 0 , |_| Ok ( ( ) ) )
116+ self . emit_enum_variant ( 0 , |_| Ok ( ( ) ) )
126117 }
127118
128119 fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
129120 where
130121 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
131122 {
132- self . emit_enum_variant ( "Some" , 1 , 1 , f)
123+ self . emit_enum_variant ( 1 , f)
133124 }
134125
135126 fn emit_seq < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
@@ -141,7 +132,7 @@ pub trait Encoder {
141132 }
142133
143134 #[ inline]
144- fn emit_seq_elt < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
135+ fn emit_seq_elt < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
145136 where
146137 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
147138 {
@@ -157,7 +148,7 @@ pub trait Encoder {
157148 }
158149
159150 #[ inline]
160- fn emit_map_elt_key < F > ( & mut self , _idx : usize , f : F ) -> Result < ( ) , Self :: Error >
151+ fn emit_map_elt_key < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
161152 where
162153 F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
163154 {
@@ -363,8 +354,8 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Rc<T> {
363354impl < S : Encoder , T : Encodable < S > > Encodable < S > for [ T ] {
364355 default fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
365356 s. emit_seq ( self . len ( ) , |s| {
366- for ( i , e ) in self . iter ( ) . enumerate ( ) {
367- s. emit_seq_elt ( i , |s| e. encode ( s) ) ?
357+ for e in self . iter ( ) {
358+ s. emit_seq_elt ( |s| e. encode ( s) ) ?
368359 }
369360 Ok ( ( ) )
370361 } )
@@ -470,12 +461,8 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
470461impl < S : Encoder , T1 : Encodable < S > , T2 : Encodable < S > > Encodable < S > for Result < T1 , T2 > {
471462 fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
472463 s. emit_enum ( |s| match * self {
473- Ok ( ref v) => {
474- s. emit_enum_variant ( "Ok" , 0 , 1 , |s| s. emit_enum_variant_arg ( true , |s| v. encode ( s) ) )
475- }
476- Err ( ref v) => {
477- s. emit_enum_variant ( "Err" , 1 , 1 , |s| s. emit_enum_variant_arg ( true , |s| v. encode ( s) ) )
478- }
464+ Ok ( ref v) => s. emit_enum_variant ( 0 , |s| s. emit_enum_variant_arg ( |s| v. encode ( s) ) ) ,
465+ Err ( ref v) => s. emit_enum_variant ( 1 , |s| s. emit_enum_variant_arg ( |s| v. encode ( s) ) ) ,
479466 } )
480467 }
481468}
@@ -494,18 +481,6 @@ macro_rules! peel {
494481 ( $name: ident, $( $other: ident, ) * ) => ( tuple! { $( $other, ) * } )
495482}
496483
497- /// Evaluates to the number of tokens passed to it.
498- ///
499- /// Logarithmic counting: every one or two recursive expansions, the number of
500- /// tokens to count is divided by two, instead of being reduced by one.
501- /// Therefore, the recursion depth is the binary logarithm of the number of
502- /// tokens to count, and the expanded tree is likewise very small.
503- macro_rules! count {
504- ( $one: tt) => ( 1usize ) ;
505- ( $( $pairs: tt $_p: tt) * ) => ( count!( $( $pairs) * ) << 1usize ) ;
506- ( $odd: tt $( $rest: tt) * ) => ( count!( $( $rest) * ) | 1usize ) ;
507- }
508-
509484macro_rules! tuple {
510485 ( ) => ( ) ;
511486 ( $( $name: ident, ) + ) => (
@@ -518,10 +493,8 @@ macro_rules! tuple {
518493 #[ allow( non_snake_case) ]
519494 fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
520495 let ( $( ref $name, ) +) = * self ;
521- let len: usize = count!( $( $name) +) ;
522- s. emit_tuple( len, |s| {
523- let mut i = 0 ;
524- $( s. emit_tuple_arg( { i+=1 ; i-1 } , |s| $name. encode( s) ) ?; ) +
496+ s. emit_tuple( |s| {
497+ $( s. emit_tuple_arg( |s| $name. encode( s) ) ?; ) +
525498 Ok ( ( ) )
526499 } )
527500 }
0 commit comments