Skip to content

Commit 81b6f8c

Browse files
committed
Add private is_empty method to RangeMut
1 parent 60a7c94 commit 81b6f8c

File tree

1 file changed

+7
-3
lines changed
  • src/liballoc/collections/btree

1 file changed

+7
-3
lines changed

src/liballoc/collections/btree/map.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<K: Clone + Ord, V: Clone> BTreeClone for BTreeMap<K, V> {
247247
// replaces every key-value pair in `self`. Since `oiter` is in sorted
248248
// order and the structure of the `BTreeMap` stays the same,
249249
// the BTree invariants are maintained at the end of the loop
250-
while siter.front != siter.back {
250+
while !siter.is_empty() {
251251
if let Some((ok, ov)) = oiter.next() {
252252
// SAFETY: This is safe because the `siter.front != siter.back` check
253253
// ensures that `siter` is nonempty
@@ -1764,7 +1764,7 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
17641764
type Item = (&'a K, &'a mut V);
17651765

17661766
fn next(&mut self) -> Option<(&'a K, &'a mut V)> {
1767-
if self.front == self.back {
1767+
if self.is_empty() {
17681768
None
17691769
} else {
17701770
unsafe {
@@ -1780,6 +1780,10 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
17801780
}
17811781

17821782
impl<'a, K, V> RangeMut<'a, K, V> {
1783+
fn is_empty(&self) -> bool {
1784+
self.front == self.back
1785+
}
1786+
17831787
unsafe fn next_unchecked(&mut self) -> (&'a mut K, &'a mut V) {
17841788
let handle = ptr::read(&self.front);
17851789

@@ -1816,7 +1820,7 @@ impl<'a, K, V> RangeMut<'a, K, V> {
18161820
#[stable(feature = "btree_range", since = "1.17.0")]
18171821
impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
18181822
fn next_back(&mut self) -> Option<(&'a K, &'a mut V)> {
1819-
if self.front == self.back { None } else { unsafe { Some(self.next_back_unchecked()) } }
1823+
if self.is_empty() { None } else { unsafe { Some(self.next_back_unchecked()) } }
18201824
}
18211825
}
18221826

0 commit comments

Comments
 (0)