Skip to content

Commit

Permalink
Remove <Cycle as Iterator>::try_fold override
Browse files Browse the repository at this point in the history
It was a incorrect optimization.
  • Loading branch information
sinkuu committed Dec 17, 2018
1 parent 1897657 commit f0483f7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/libcore/iter/mod.rs
Expand Up @@ -649,19 +649,6 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
_ => (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")]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tests/iter.rs
Expand Up @@ -1003,6 +1003,8 @@ fn test_cycle() {
assert_eq!(it.next(), None);

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]
Expand Down

0 comments on commit f0483f7

Please sign in to comment.