Skip to content

Commit

Permalink
Avoid closures in OnceWith and Successors
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Aug 12, 2019
1 parent 7539fc6 commit 40ecbc7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libcore/iter/sources.rs
Expand Up @@ -394,7 +394,8 @@ impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {

#[inline]
fn next(&mut self) -> Option<A> {
self.gen.take().map(|f| f())
let f = self.gen.take()?;
Some(f())
}

#[inline]
Expand Down Expand Up @@ -608,10 +609,9 @@ impl<T, F> Iterator for Successors<T, F>

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.next.take().map(|item| {
self.next = (self.succ)(&item);
item
})
let item = self.next.take()?;
self.next = (self.succ)(&item);
Some(item)
}

#[inline]
Expand Down

0 comments on commit 40ecbc7

Please sign in to comment.