File tree Expand file tree Collapse file tree 2 files changed +4
-19
lines changed Expand file tree Collapse file tree 2 files changed +4
-19
lines changed Original file line number Diff line number Diff line change @@ -209,10 +209,6 @@ where
209
209
Self : Sized ,
210
210
F : FnMut ( B , Self :: Item ) -> B ,
211
211
{
212
- if self . remainder . is_some ( ) {
213
- return init;
214
- }
215
-
216
212
let mut accum = init;
217
213
let inner_len = self . iter . size ( ) ;
218
214
let mut i = 0 ;
@@ -233,20 +229,8 @@ where
233
229
i += N ;
234
230
}
235
231
236
- let remainder = inner_len % N ;
237
-
238
- let mut tail = MaybeUninit :: uninit_array ( ) ;
239
- let mut guard = array:: Guard { array_mut : & mut tail, initialized : 0 } ;
240
- for i in 0 ..remainder {
241
- // SAFETY: the remainder was not visited by the previous loop, so we're still only
242
- // accessing each element once
243
- let val = unsafe { self . iter . __iterator_get_unchecked ( inner_len - remainder + i) } ;
244
- guard. array_mut [ i] . write ( val) ;
245
- guard. initialized = i + 1 ;
246
- }
247
- mem:: forget ( guard) ;
248
- // SAFETY: the loop above initialized elements up to the `remainder` index
249
- self . remainder = Some ( unsafe { array:: IntoIter :: new_unchecked ( tail, 0 ..remainder) } ) ;
232
+ // unlike try_fold this method does not need to take care of the remainder
233
+ // since `self` will be dropped
250
234
251
235
accum
252
236
}
Original file line number Diff line number Diff line change @@ -139,7 +139,8 @@ fn test_iterator_array_chunks_fold() {
139
139
let result =
140
140
( 0 ..10 ) . map ( |_| CountDrop :: new ( & count) ) . array_chunks :: < 3 > ( ) . fold ( 0 , |acc, _item| acc + 1 ) ;
141
141
assert_eq ! ( result, 3 ) ;
142
- assert_eq ! ( count. get( ) , 10 ) ;
142
+ // fold impls may or may not process the remainder
143
+ assert ! ( count. get( ) <= 10 && count. get( ) >= 9 ) ;
143
144
}
144
145
145
146
#[ test]
You can’t perform that action at this time.
0 commit comments