Remove <Cycle as Iterator>::try_fold override

It was a incorrect optimization.
This commit is contained in:
Shotaro Yamada 2018-12-17 09:35:28 +09:00
parent 1897657ef0
commit f0483f76e6
2 changed files with 2 additions and 13 deletions

View File

@ -649,19 +649,6 @@ fn size_hint(&self) -> (usize, Option<usize>) {
_ => (usize::MAX, None) _ => (usize::MAX, None)
} }
} }
#[inline]
fn try_fold<Acc, F, R>(&mut self, init: Acc, mut f: F) -> R where
Self: Sized, F: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
{
let mut accum = init;
while let Some(x) = self.iter.next() {
accum = f(accum, x)?;
accum = self.iter.try_fold(accum, &mut f)?;
self.iter = self.orig.clone();
}
Try::from_ok(accum)
}
} }
#[stable(feature = "fused", since = "1.26.0")] #[stable(feature = "fused", since = "1.26.0")]

View File

@ -1003,6 +1003,8 @@ fn test_cycle() {
assert_eq!(it.next(), None); assert_eq!(it.next(), None);
assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0); assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0);
assert_eq!(once(1).cycle().skip(1).take(4).fold(0, |acc, x| acc + x), 4);
} }
#[test] #[test]