@@ -19,6 +19,7 @@ pub struct ByKey<F> {
19
19
}
20
20
21
21
impl < F > ByKey < F > {
22
+ #[ inline]
22
23
pub ( crate ) fn new ( key : F ) -> Self {
23
24
Self { key }
24
25
}
31
32
K : PartialEq ,
32
33
{
33
34
type Output = bool ;
34
-
35
+ # [ inline ]
35
36
extern "rust-call" fn call_once ( mut self , args : ( & T , & T ) ) -> Self :: Output {
36
37
( self . key ) ( args. 0 ) == ( self . key ) ( args. 1 )
37
38
}
43
44
F : FnMut ( & T ) -> K ,
44
45
K : PartialEq ,
45
46
{
47
+ #[ inline]
46
48
extern "rust-call" fn call_mut ( & mut self , args : ( & T , & T ) ) -> Self :: Output {
47
49
( self . key ) ( args. 0 ) == ( self . key ) ( args. 1 )
48
50
}
62
64
pub struct ByPartialEq ;
63
65
64
66
impl ByPartialEq {
67
+ #[ inline]
65
68
pub ( crate ) fn new ( ) -> Self {
66
69
Self
67
70
}
@@ -70,14 +73,15 @@ impl ByPartialEq {
70
73
#[ unstable( feature = "iter_dedup" , reason = "recently added" , issue = "83748" ) ]
71
74
impl < T : PartialEq > FnOnce < ( & T , & T ) > for ByPartialEq {
72
75
type Output = bool ;
73
-
76
+ # [ inline ]
74
77
extern "rust-call" fn call_once ( self , args : ( & T , & T ) ) -> Self :: Output {
75
78
args. 0 == args. 1
76
79
}
77
80
}
78
81
79
82
#[ unstable( feature = "iter_dedup" , reason = "recently added" , issue = "83748" ) ]
80
83
impl < T : PartialEq > FnMut < ( & T , & T ) > for ByPartialEq {
84
+ #[ inline]
81
85
extern "rust-call" fn call_mut ( & mut self , args : ( & T , & T ) ) -> Self :: Output {
82
86
args. 0 == args. 1
83
87
}
@@ -93,23 +97,23 @@ impl<T: PartialEq> FnMut<(&T, &T)> for ByPartialEq {
93
97
/// [`Iterator::dedup_by`]: Iterator::dedup_by
94
98
/// [`Iterator::dedup_by_key`]: Iterator::dedup_by_key
95
99
#[ unstable( feature = "iter_dedup" , reason = "recently added" , issue = "83748" ) ]
96
- #[ derive( Debug , Clone , Copy ) ]
100
+ #[ derive( Debug , Clone ) ]
97
101
pub struct Dedup < I , F >
98
102
where
99
103
I : Iterator ,
100
104
{
101
105
inner : I ,
102
106
same_bucket : F ,
103
- last : Option < I :: Item > ,
107
+ last : Option < Option < I :: Item > > ,
104
108
}
105
109
106
110
impl < I , F > Dedup < I , F >
107
111
where
108
112
I : Iterator ,
109
113
{
114
+ #[ inline]
110
115
pub ( crate ) fn new ( inner : I , same_bucket : F ) -> Self {
111
- let mut inner = inner;
112
- Self { last : inner. next ( ) , inner, same_bucket }
116
+ Self { inner, same_bucket, last : None }
113
117
}
114
118
}
115
119
@@ -121,8 +125,15 @@ where
121
125
{
122
126
type Item = I :: Item ;
123
127
128
+ #[ inline]
124
129
fn next ( & mut self ) -> Option < Self :: Item > {
125
- let last_item = self . last . as_ref ( ) ?;
130
+ if self . last . is_none ( ) {
131
+ self . last = Some ( self . inner . next ( ) )
132
+ }
133
+
134
+ let last = self . last . as_mut ( ) . unwrap ( ) ;
135
+ let last_item = last. as_ref ( ) ?;
136
+
126
137
let mut next = loop {
127
138
let curr = self . inner . next ( ) ;
128
139
if let Some ( curr_item) = & curr {
@@ -134,10 +145,11 @@ where
134
145
}
135
146
} ;
136
147
137
- swap ( & mut self . last , & mut next) ;
148
+ swap ( last, & mut next) ;
138
149
next
139
150
}
140
151
152
+ #[ inline]
141
153
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
142
154
let min = self . last . as_ref ( ) . map ( |_| 1 ) . unwrap_or ( 0 ) ;
143
155
let max = self . inner . size_hint ( ) . 1 ;
@@ -153,6 +165,7 @@ where
153
165
{
154
166
type Source = S ;
155
167
168
+ #[ inline]
156
169
unsafe fn as_inner ( & mut self ) -> & mut Self :: Source {
157
170
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
158
171
unsafe { SourceIter :: as_inner ( & mut self . inner ) }
0 commit comments