Skip to content

Commit 398fd38

Browse files
bors[bot]phimuemue
andauthored
Merge #437
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 <[email protected]>
2 parents 2c6b6ed + 7baf163 commit 398fd38

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

src/multipeek_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ impl<I> Iterator for MultiPeek<I>
8282

8383
fn next(&mut self) -> Option<I::Item> {
8484
self.index = 0;
85-
if self.buf.is_empty() {
86-
self.iter.next()
87-
} else {
88-
self.buf.pop_front()
89-
}
85+
self.buf.pop_front().or_else(|| self.iter.next())
9086
}
9187

9288
fn size_hint(&self) -> (usize, Option<usize>) {

src/put_back_n_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ impl<I: Iterator> Iterator for PutBackN<I> {
4848
type Item = I::Item;
4949
#[inline]
5050
fn next(&mut self) -> Option<I::Item> {
51-
if self.top.is_empty() {
52-
self.iter.next()
53-
} else {
54-
self.top.pop()
55-
}
51+
self.top.pop().or_else(|| self.iter.next())
5652
}
5753

5854
#[inline]

0 commit comments

Comments
 (0)