about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-07-03 12:13:00 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-07-04 00:46:50 +1000
commitf19fb2459f4fc695225f996692a6a6b30b801ee9 (patch)
treeb6bd30b5b071b88c8f394210f10e6f347ccf9bf3 /src/libextra
parent920780258999aa4a2669a594464cda780798d35f (diff)
downloadrust-f19fb2459f4fc695225f996692a6a6b30b801ee9.tar.gz
rust-f19fb2459f4fc695225f996692a6a6b30b801ee9.zip
Remove standalone comparison functions in vec, make the trait impls better.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/crypto/sha1.rs5
-rw-r--r--src/libextra/flatpipes.rs7
-rw-r--r--src/libextra/num/bigint.rs18
3 files changed, 14 insertions, 16 deletions
diff --git a/src/libextra/crypto/sha1.rs b/src/libextra/crypto/sha1.rs
index 238e4a4d238..0f2d44f57e3 100644
--- a/src/libextra/crypto/sha1.rs
+++ b/src/libextra/crypto/sha1.rs
@@ -240,7 +240,6 @@ impl Digest for Sha1 {
 
 #[cfg(test)]
 mod tests {
-    use std::vec;
 
     use digest::{Digest, DigestUtil};
     use sha1::Sha1;
@@ -337,7 +336,7 @@ mod tests {
         for tests.iter().advance |t| {
             (*sh).input_str(t.input);
             sh.result(out);
-            assert!(vec::eq(t.output, out));
+            assert!(t.output.as_slice() == out);
 
             let out_str = (*sh).result_str();
             assert_eq!(out_str.len(), 40);
@@ -357,7 +356,7 @@ mod tests {
                 left = left - take;
             }
             sh.result(out);
-            assert!(vec::eq(t.output, out));
+            assert!(t.output.as_slice() == out);
 
             let out_str = (*sh).result_str();
             assert_eq!(out_str.len(), 40);
diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs
index e8bdc951ca4..de0a988f94c 100644
--- a/src/libextra/flatpipes.rs
+++ b/src/libextra/flatpipes.rs
@@ -55,7 +55,6 @@ use std::io;
 use std::comm::GenericChan;
 use std::comm::GenericPort;
 use std::sys::size_of;
-use std::vec;
 
 /**
 A FlatPort, consisting of a `BytePort` that receives byte vectors,
@@ -274,7 +273,7 @@ impl<T,U:Unflattener<T>,P:BytePort> GenericPort<T> for FlatPort<T, U, P> {
             }
         };
 
-        if vec::eq(command, CONTINUE) {
+        if CONTINUE.as_slice() == command {
             let msg_len = match self.byte_port.try_recv(size_of::<u64>()) {
                 Some(bytes) => {
                     io::u64_from_be_bytes(bytes, 0, size_of::<u64>())
@@ -931,7 +930,7 @@ mod test {
         fn test_try_recv_none3<P:BytePort>(loader: PortLoader<P>) {
             static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD];
             // The control word is followed by garbage
-            let bytes = CONTINUE.to_owned() + [0];
+            let bytes = CONTINUE.to_owned() + &[0u8];
             let port = loader(bytes);
             let res: Option<int> = port.try_recv();
             assert!(res.is_none());
@@ -955,7 +954,7 @@ mod test {
                     1, sys::size_of::<u64>()) |len_bytes| {
                     len_bytes.to_owned()
                 };
-                let bytes = CONTINUE.to_owned() + len_bytes + [0, 0, 0, 0];
+                let bytes = CONTINUE.to_owned() + len_bytes + &[0u8, 0, 0, 0];
 
                 let port = loader(bytes);
 
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs
index 338fd86ad1e..a0b95924e09 100644
--- a/src/libextra/num/bigint.rs
+++ b/src/libextra/num/bigint.rs
@@ -207,7 +207,7 @@ impl Add<BigUint, BigUint> for BigUint {
         let new_len = uint::max(self.data.len(), other.data.len());
 
         let mut carry = 0;
-        let sum = do vec::from_fn(new_len) |i| {
+        let mut sum = do vec::from_fn(new_len) |i| {
             let ai = if i < self.data.len()  { self.data[i]  } else { 0 };
             let bi = if i < other.data.len() { other.data[i] } else { 0 };
             let (hi, lo) = BigDigit::from_uint(
@@ -216,8 +216,8 @@ impl Add<BigUint, BigUint> for BigUint {
             carry = hi;
             lo
         };
-        if carry == 0 { return BigUint::new(sum) };
-        return BigUint::new(sum + [carry]);
+        if carry != 0 { sum.push(carry); }
+        return BigUint::new(sum);
     }
 }
 
@@ -284,15 +284,15 @@ impl Mul<BigUint, BigUint> for BigUint {
             if n == 1 { return copy *a; }
 
             let mut carry = 0;
-            let prod = do a.data.iter().transform |ai| {
+            let mut prod = do a.data.iter().transform |ai| {
                 let (hi, lo) = BigDigit::from_uint(
                     (*ai as uint) * (n as uint) + (carry as uint)
                 );
                 carry = hi;
                 lo
             }.collect::<~[BigDigit]>();
-            if carry == 0 { return BigUint::new(prod) };
-            return BigUint::new(prod + [carry]);
+            if carry != 0 { prod.push(carry); }
+            return BigUint::new(prod);
         }
 
 
@@ -621,15 +621,15 @@ impl BigUint {
         if n_bits == 0 || self.is_zero() { return copy *self; }
 
         let mut carry = 0;
-        let shifted = do self.data.iter().transform |elem| {
+        let mut shifted = do self.data.iter().transform |elem| {
             let (hi, lo) = BigDigit::from_uint(
                 (*elem as uint) << n_bits | (carry as uint)
             );
             carry = hi;
             lo
         }.collect::<~[BigDigit]>();
-        if carry == 0 { return BigUint::new(shifted); }
-        return BigUint::new(shifted + [carry]);
+        if carry != 0 { shifted.push(carry); }
+        return BigUint::new(shifted);
     }