Skip to content

Commit 6e055c3

Browse files
committed
Auto merge of #22958 - laijs:option_map_for_iter_map, r=alexcrichton
Signed-off-by: Lai Jiangshan <[email protected]>
2 parents fed1249 + cd65156 commit 6e055c3

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/libcore/iter.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -1570,24 +1570,13 @@ pub struct Map<I, F> {
15701570
f: F,
15711571
}
15721572

1573-
impl<I: Iterator, F, B> Map<I, F> where F: FnMut(I::Item) -> B {
1574-
#[inline]
1575-
fn do_map(&mut self, elt: Option<I::Item>) -> Option<B> {
1576-
match elt {
1577-
Some(a) => Some((self.f)(a)),
1578-
_ => None
1579-
}
1580-
}
1581-
}
1582-
15831573
#[stable(feature = "rust1", since = "1.0.0")]
15841574
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B {
15851575
type Item = B;
15861576

15871577
#[inline]
15881578
fn next(&mut self) -> Option<B> {
1589-
let next = self.iter.next();
1590-
self.do_map(next)
1579+
self.iter.next().map(|a| (self.f)(a))
15911580
}
15921581

15931582
#[inline]
@@ -1602,8 +1591,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where
16021591
{
16031592
#[inline]
16041593
fn next_back(&mut self) -> Option<B> {
1605-
let next = self.iter.next_back();
1606-
self.do_map(next)
1594+
self.iter.next_back().map(|a| (self.f)(a))
16071595
}
16081596
}
16091597

@@ -1618,8 +1606,7 @@ impl<B, I: RandomAccessIterator, F> RandomAccessIterator for Map<I, F> where
16181606

16191607
#[inline]
16201608
fn idx(&mut self, index: usize) -> Option<B> {
1621-
let elt = self.iter.idx(index);
1622-
self.do_map(elt)
1609+
self.iter.idx(index).map(|a| (self.f)(a))
16231610
}
16241611
}
16251612

0 commit comments

Comments
 (0)