about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorCharles Gleason <charles_gleason@alumni.brown.edu>2020-01-28 11:46:49 -0500
committerCharles Gleason <charles_gleason@alumni.brown.edu>2020-01-28 11:46:49 -0500
commit81b6f8c3fc9098e7b1b6aad230ea7770d03070bc (patch)
treea13cfad117aa2c7fc3ae8ce8ae12c09f001b2980 /src/liballoc
parent60a7c9421e78a29610e019b4030ca011bcd0bfd5 (diff)
downloadrust-81b6f8c3fc9098e7b1b6aad230ea7770d03070bc.tar.gz
rust-81b6f8c3fc9098e7b1b6aad230ea7770d03070bc.zip
Add private is_empty method to RangeMut
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/collections/btree/map.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs
index 58cb561938a..d0c56d83d72 100644
--- a/src/liballoc/collections/btree/map.rs
+++ b/src/liballoc/collections/btree/map.rs
@@ -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
@@ -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 {
@@ -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);
 
@@ -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()) } }
     }
 }