Skip to content

Commit

Permalink
Merge #437
Browse files Browse the repository at this point in the history
437: Simpl is empty r=jswrenn a=phimuemue

Taking inspiration from #303 (comment), I think we could exploit that `pop`/`pop_front` return `Option`.

Note: https://godbolt.org/z/WVTD7m seems to indicate that the compiler is doing a good job at optimizing either version.

Co-authored-by: philipp <descpl@yahoo.de>
  • Loading branch information
bors[bot] and phimuemue committed May 6, 2020
2 parents 2c6b6ed + 7baf163 commit 398fd38
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/multipeek_impl.rs
Expand Up @@ -82,11 +82,7 @@ impl<I> Iterator for MultiPeek<I>

fn next(&mut self) -> Option<I::Item> {
self.index = 0;
if self.buf.is_empty() {
self.iter.next()
} else {
self.buf.pop_front()
}
self.buf.pop_front().or_else(|| self.iter.next())
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
6 changes: 1 addition & 5 deletions src/put_back_n_impl.rs
Expand Up @@ -48,11 +48,7 @@ impl<I: Iterator> Iterator for PutBackN<I> {
type Item = I::Item;
#[inline]
fn next(&mut self) -> Option<I::Item> {
if self.top.is_empty() {
self.iter.next()
} else {
self.top.pop()
}
self.top.pop().or_else(|| self.iter.next())
}

#[inline]
Expand Down

0 comments on commit 398fd38

Please sign in to comment.