Skip to content

Commit 3fd3716

Browse files
committed
Port rust-lang/rust changes for Iterator, Extend
- #62316: When possible without changing semantics, implement Iterator::last in terms of DoubleEndedIterator::next_back for types in liballoc and libcore - #59740: Use for_each to extend collections
1 parent 3c1b1f5 commit 3fd3716

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/binary_heap.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,11 @@ impl<'a, T> Iterator for Iter<'a, T> {
14121412
fn size_hint(&self) -> (usize, Option<usize>) {
14131413
self.iter.size_hint()
14141414
}
1415+
1416+
#[inline]
1417+
fn last(self) -> Option<&'a T> {
1418+
self.iter.last()
1419+
}
14151420
}
14161421

14171422
// #[stable(feature = "rust1", since = "1.0.0")]
@@ -1652,9 +1657,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
16521657

16531658
self.reserve(lower);
16541659

1655-
for elem in iterator {
1656-
self.push(elem);
1657-
}
1660+
iterator.for_each(move |elem| self.push(elem));
16581661
}
16591662
}
16601663

0 commit comments

Comments
 (0)