]> git.lizzy.rs Git - rust.git/commitdiff
remove obsolete purity workarounds
authorDaniel Micay <danielmicay@gmail.com>
Fri, 22 Mar 2013 22:07:09 +0000 (18:07 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Fri, 22 Mar 2013 22:08:56 +0000 (18:08 -0400)
src/libstd/priority_queue.rs
src/libstd/treemap.rs

index 03d518f1f6300d714c60d1dc843cb75dd6151912..ff00d26882d32f22aaff4bef7f2047f1e5235dab 100644 (file)
@@ -112,7 +112,7 @@ fn to_sorted_vec(self) -> ~[T] {
         while end > 1 {
             end -= 1;
             q.data[end] <-> q.data[0];
-            unsafe { q.siftdown_range(0, end) } // purity-checking workaround
+            q.siftdown_range(0, end)
         }
         q.to_vec()
     }
@@ -126,7 +126,7 @@ fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
         let mut n = q.len() / 2;
         while n > 0 {
             n -= 1;
-            unsafe { q.siftdown(n) }; // purity-checking workaround
+            q.siftdown(n)
         }
         q
     }
index e42c65907244122ab887dbb42a1a4ffe8520da55..242ffd07881dee00fb445e1dccaf01ba94916671 100644 (file)
@@ -43,11 +43,9 @@ fn eq(&self, other: &TreeMap<K, V>) -> bool {
             let mut x = self.iter();
             let mut y = other.iter();
             for self.len().times {
-                unsafe { // unsafe as a purity workaround
-                    if map_next(&mut x).unwrap() !=
-                       map_next(&mut y).unwrap() {
-                        return false
-                    }
+                if map_next(&mut x).unwrap() !=
+                   map_next(&mut y).unwrap() {
+                    return false
                 }
             }
             true
@@ -64,12 +62,10 @@ fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
 
     let (a_len, b_len) = (a.len(), b.len());
     for uint::min(a_len, b_len).times {
-        unsafe { // purity workaround
-            let (key_a,_) = map_next(&mut x).unwrap();
-            let (key_b,_) = map_next(&mut y).unwrap();
-            if *key_a < *key_b { return true; }
-            if *key_a > *key_b { return false; }
-        }
+        let (key_a,_) = map_next(&mut x).unwrap();
+        let (key_b,_) = map_next(&mut y).unwrap();
+        if *key_a < *key_b { return true; }
+        if *key_a > *key_b { return false; }
     };
 
     a_len < b_len
@@ -311,17 +307,15 @@ fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
     fn is_disjoint(&self, other: &TreeSet<T>) -> bool {
         let mut x = self.iter();
         let mut y = other.iter();
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
-            while a.is_some() && b.is_some() {
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
-                match a1.cmp(b1) {
-                  Less => a = set_next(&mut x),
-                  Greater => b = set_next(&mut y),
-                  Equal => return false
-                }
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
+        while a.is_some() && b.is_some() {
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
+            match a1.cmp(b1) {
+              Less => a = set_next(&mut x),
+              Greater => b = set_next(&mut y),
+              Equal => return false
             }
         }
         true
@@ -337,25 +331,23 @@ fn is_subset(&self, other: &TreeSet<T>) -> bool {
     fn is_superset(&self, other: &TreeSet<T>) -> bool {
         let mut x = self.iter();
         let mut y = other.iter();
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
-            while b.is_some() {
-                if a.is_none() {
-                    return false
-                }
-
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
+        while b.is_some() {
+            if a.is_none() {
+                return false
+            }
 
-                match a1.cmp(b1) {
-                  Less => (),
-                  Greater => return false,
-                  Equal => b = set_next(&mut y),
-                }
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
 
-                a = set_next(&mut x);
+            match a1.cmp(b1) {
+              Less => (),
+              Greater => return false,
+              Equal => b = set_next(&mut y),
             }
+
+            a = set_next(&mut x);
         }
         true
     }
@@ -365,29 +357,27 @@ fn difference(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
         let mut x = self.iter();
         let mut y = other.iter();
 
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
 
-            while a.is_some() {
-                if b.is_none() {
-                    return do a.while_some() |a1| {
-                        if f(a1) { set_next(&mut x) } else { None }
-                    }
+        while a.is_some() {
+            if b.is_none() {
+                return do a.while_some() |a1| {
+                    if f(a1) { set_next(&mut x) } else { None }
                 }
+            }
 
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
 
-                let cmp = a1.cmp(b1);
+            let cmp = a1.cmp(b1);
 
-                if cmp == Less {
-                    if !f(a1) { return }
-                    a = set_next(&mut x);
-                } else {
-                    if cmp == Equal { a = set_next(&mut x) }
-                    b = set_next(&mut y);
-                }
+            if cmp == Less {
+                if !f(a1) { return }
+                a = set_next(&mut x);
+            } else {
+                if cmp == Equal { a = set_next(&mut x) }
+                b = set_next(&mut y);
             }
         }
     }
@@ -398,37 +388,35 @@ fn symmetric_difference(&self, other: &TreeSet<T>,
         let mut x = self.iter();
         let mut y = other.iter();
 
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
 
-            while a.is_some() {
-                if b.is_none() {
-                    return do a.while_some() |a1| {
-                        if f(a1) { set_next(&mut x) } else { None }
-                    }
+        while a.is_some() {
+            if b.is_none() {
+                return do a.while_some() |a1| {
+                    if f(a1) { set_next(&mut x) } else { None }
                 }
+            }
 
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
 
-                let cmp = a1.cmp(b1);
+            let cmp = a1.cmp(b1);
 
-                if cmp == Less {
-                    if !f(a1) { return }
-                    a = set_next(&mut x);
+            if cmp == Less {
+                if !f(a1) { return }
+                a = set_next(&mut x);
+            } else {
+                if cmp == Greater {
+                    if !f(b1) { return }
                 } else {
-                    if cmp == Greater {
-                        if !f(b1) { return }
-                    } else {
-                        a = set_next(&mut x);
-                    }
-                    b = set_next(&mut y);
+                    a = set_next(&mut x);
                 }
+                b = set_next(&mut y);
             }
-            do b.while_some |b1| {
-                if f(b1) { set_next(&mut y) } else { None }
-            }
+        }
+        do b.while_some |b1| {
+            if f(b1) { set_next(&mut y) } else { None }
         }
     }
 
@@ -437,24 +425,22 @@ fn intersection(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
         let mut x = self.iter();
         let mut y = other.iter();
 
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
 
-            while a.is_some() && b.is_some() {
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
+        while a.is_some() && b.is_some() {
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
 
-                let cmp = a1.cmp(b1);
+            let cmp = a1.cmp(b1);
 
-                if cmp == Less {
-                    a = set_next(&mut x);
-                } else {
-                    if cmp == Equal {
-                        if !f(a1) { return }
-                    }
-                    b = set_next(&mut y);
+            if cmp == Less {
+                a = set_next(&mut x);
+            } else {
+                if cmp == Equal {
+                    if !f(a1) { return }
                 }
+                b = set_next(&mut y);
             }
         }
     }
@@ -464,36 +450,34 @@ fn union(&self, other: &TreeSet<T>, f: &fn(&T) -> bool) {
         let mut x = self.iter();
         let mut y = other.iter();
 
-        unsafe { // purity workaround
-            let mut a = set_next(&mut x);
-            let mut b = set_next(&mut y);
+        let mut a = set_next(&mut x);
+        let mut b = set_next(&mut y);
 
-            while a.is_some() {
-                if b.is_none() {
-                    return do a.while_some() |a1| {
-                        if f(a1) { set_next(&mut x) } else { None }
-                    }
+        while a.is_some() {
+            if b.is_none() {
+                return do a.while_some() |a1| {
+                    if f(a1) { set_next(&mut x) } else { None }
                 }
+            }
 
-                let a1 = a.unwrap();
-                let b1 = b.unwrap();
+            let a1 = a.unwrap();
+            let b1 = b.unwrap();
 
-                let cmp = a1.cmp(b1);
+            let cmp = a1.cmp(b1);
 
-                if cmp == Greater {
-                    if !f(b1) { return }
+            if cmp == Greater {
+                if !f(b1) { return }
+                b = set_next(&mut y);
+            } else {
+                if !f(a1) { return }
+                if cmp == Equal {
                     b = set_next(&mut y);
-                } else {
-                    if !f(a1) { return }
-                    if cmp == Equal {
-                        b = set_next(&mut y);
-                    }
-                    a = set_next(&mut x);
                 }
+                a = set_next(&mut x);
             }
-            do b.while_some |b1| {
-                if f(b1) { set_next(&mut y) } else { None }
-            }
+        }
+        do b.while_some |b1| {
+            if f(b1) { set_next(&mut y) } else { None }
         }
     }
 }