@@ -44,13 +44,7 @@ pub trait Encoder {
44
44
f ( self )
45
45
}
46
46
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 >
54
48
where
55
49
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
56
50
{
@@ -65,47 +59,44 @@ pub trait Encoder {
65
59
// optimization that would otherwise be necessary here, likely due to the
66
60
// multiple levels of inlining and const-prop that are needed.
67
61
#[ 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 > {
72
63
self . emit_usize ( ID )
73
64
}
74
65
75
66
#[ 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 >
77
68
where
78
69
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
79
70
{
80
71
f ( self )
81
72
}
82
73
83
74
#[ 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 >
85
76
where
86
77
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
87
78
{
88
79
f ( self )
89
80
}
90
81
91
82
#[ 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 >
93
84
where
94
85
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
95
86
{
96
87
f ( self )
97
88
}
98
89
99
90
#[ 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 >
101
92
where
102
93
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
103
94
{
104
95
f ( self )
105
96
}
106
97
107
98
#[ 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 >
109
100
where
110
101
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
111
102
{
@@ -122,14 +113,14 @@ pub trait Encoder {
122
113
123
114
#[ inline]
124
115
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 ( ( ) ) )
126
117
}
127
118
128
119
fn emit_option_some < F > ( & mut self , f : F ) -> Result < ( ) , Self :: Error >
129
120
where
130
121
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
131
122
{
132
- self . emit_enum_variant ( "Some" , 1 , 1 , f)
123
+ self . emit_enum_variant ( 1 , f)
133
124
}
134
125
135
126
fn emit_seq < F > ( & mut self , len : usize , f : F ) -> Result < ( ) , Self :: Error >
@@ -141,7 +132,7 @@ pub trait Encoder {
141
132
}
142
133
143
134
#[ 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 >
145
136
where
146
137
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
147
138
{
@@ -157,7 +148,7 @@ pub trait Encoder {
157
148
}
158
149
159
150
#[ 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 >
161
152
where
162
153
F : FnOnce ( & mut Self ) -> Result < ( ) , Self :: Error > ,
163
154
{
@@ -363,8 +354,8 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Rc<T> {
363
354
impl < S : Encoder , T : Encodable < S > > Encodable < S > for [ T ] {
364
355
default fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
365
356
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) ) ?
368
359
}
369
360
Ok ( ( ) )
370
361
} )
@@ -470,12 +461,8 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Option<T> {
470
461
impl < S : Encoder , T1 : Encodable < S > , T2 : Encodable < S > > Encodable < S > for Result < T1 , T2 > {
471
462
fn encode ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
472
463
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) ) ) ,
479
466
} )
480
467
}
481
468
}
@@ -494,18 +481,6 @@ macro_rules! peel {
494
481
( $name: ident, $( $other: ident, ) * ) => ( tuple! { $( $other, ) * } )
495
482
}
496
483
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
-
509
484
macro_rules! tuple {
510
485
( ) => ( ) ;
511
486
( $( $name: ident, ) + ) => (
@@ -518,10 +493,8 @@ macro_rules! tuple {
518
493
#[ allow( non_snake_case) ]
519
494
fn encode( & self , s: & mut S ) -> Result <( ) , S :: Error > {
520
495
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) ) ?; ) +
525
498
Ok ( ( ) )
526
499
} )
527
500
}
0 commit comments