Skip to content

Commit

Permalink
Add private is_empty method to RangeMut
Browse files Browse the repository at this point in the history
  • Loading branch information
crgl committed Jan 28, 2020
1 parent 60a7c94 commit 81b6f8c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/liballoc/collections/btree/map.rs
Expand Up @@ -247,7 +247,7 @@ impl<K: Clone + Ord, V: Clone> BTreeClone for BTreeMap<K, V> {
// replaces every key-value pair in `self`. Since `oiter` is in sorted
// order and the structure of the `BTreeMap` stays the same,
// the BTree invariants are maintained at the end of the loop
while siter.front != siter.back {
while !siter.is_empty() {
if let Some((ok, ov)) = oiter.next() {
// SAFETY: This is safe because the `siter.front != siter.back` check
// ensures that `siter` is nonempty
Expand Down Expand Up @@ -1764,7 +1764,7 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
type Item = (&'a K, &'a mut V);

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

impl<'a, K, V> RangeMut<'a, K, V> {
fn is_empty(&self) -> bool {
self.front == self.back
}

unsafe fn next_unchecked(&mut self) -> (&'a mut K, &'a mut V) {
let handle = ptr::read(&self.front);

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

Expand Down

0 comments on commit 81b6f8c

Please sign in to comment.