]> git.lizzy.rs Git - rust.git/commitdiff
impl Clone for ~T, ~[T], ~str
authorBen Striegel <ben.striegel@gmail.com>
Fri, 15 Mar 2013 22:26:59 +0000 (18:26 -0400)
committerBen Striegel <ben.striegel@gmail.com>
Fri, 15 Mar 2013 22:26:59 +0000 (18:26 -0400)
src/libcore/clone.rs
src/libcore/str.rs
src/libcore/unstable/global.rs
src/libcore/vec.rs
src/libstd/arc.rs
src/libstd/sync.rs
src/libsyntax/ext/pipes/liveness.rs

index 297c4438039f097b63e9528a08fc4ef18266ee66..af44f68601bc24b6c197eb13450c2262c0c29756 100644 (file)
@@ -20,6 +20,11 @@ impl Clone for () {
     fn clone(&self) -> () { () }
 }
 
+impl<T:Clone> Clone for ~T {
+    #[inline(always)]
+    fn clone(&self) -> ~T { ~(**self).clone() }
+}
+
 macro_rules! clone_impl(
     ($t:ty) => {
         impl Clone for $t {
index 4163679a98d744b889a82fdb30498b85af5c27ed..67a3f0d5d722d4ebfb1b21a6c1479670f705aed7 100644 (file)
@@ -20,6 +20,7 @@
 use at_vec;
 use cast;
 use char;
+use clone::Clone;
 use cmp::{Equiv, TotalOrd, Ordering, Less, Equal, Greater};
 use libc;
 use option::{None, Option, Some};
@@ -2433,6 +2434,13 @@ fn push_char(&mut self, c: char) {
     }
 }
 
+impl Clone for ~str {
+    #[inline(always)]
+    fn clone(&self) -> ~str {
+        self.to_str()  // hilarious
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use char;
index 654bf18a5b6b9ffbf232a0a5a318ccf398df523b..d8ded635291dce89cd7690f2144334ff553b9452 100644 (file)
@@ -68,11 +68,11 @@ unsafe fn global_data_clone_create_<T:Owned + Clone>(
         match value {
             None => {
                 let value = create();
-                clone_value = Some(value.clone());
+                clone_value = Some((*value).clone());
                 Some(value)
             }
             Some(value) => {
-                clone_value = Some(value.clone());
+                clone_value = Some((*value).clone());
                 Some(value)
             }
         }
@@ -193,7 +193,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
             // Successfully installed the global pointer
 
             // Take a handle to return
-            let clone = state.clone();
+            let clone = (*state).clone();
 
             // Install a runtime exit function to destroy the global object
             do at_exit {
index 360940236ca1f1e6d04b2cb7552b72842fc379d1..f11a63a787d7c5d6115b2a2fe9ac3801c09591e2 100644 (file)
@@ -15,6 +15,7 @@
 use container::{Container, Mutable};
 use cast;
 use cmp::{Eq, Equiv, Ord, TotalOrd, Ordering, Less, Equal, Greater};
+use clone::Clone;
 use iter::BaseIter;
 use iter;
 use kinds::Copy;
@@ -2501,6 +2502,18 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
     }
 }
 
+impl<A:Clone> Clone for ~[A] {
+    #[inline]
+    fn clone(&self) -> ~[A] {
+        let mut dolly = ~[];
+        vec::reserve(&mut dolly, self.len());
+        for self.each |item| {
+            dolly.push(item.clone());
+        }
+        return dolly;
+    }
+}
+
 // ___________________________________________________________________________
 
 #[cfg(test)]
index b91af9a00690359fa865797681fe984c482e2b9d..bd2f641c017f1f5d94ba0dc068ac0516c796f2b7 100644 (file)
@@ -572,7 +572,7 @@ pub fn test_mutex_arc_poison() {
     #[test] #[should_fail] #[ignore(cfg(windows))]
     pub fn test_rw_arc_poison_wr() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.write |one| {
                 fail_unless!(*one == 2);
@@ -585,7 +585,7 @@ pub fn test_rw_arc_poison_wr() {
     #[test] #[should_fail] #[ignore(cfg(windows))]
     pub fn test_rw_arc_poison_ww() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.write |one| {
                 fail_unless!(*one == 2);
@@ -598,7 +598,7 @@ pub fn test_rw_arc_poison_ww() {
     #[test] #[should_fail] #[ignore(cfg(windows))]
     pub fn test_rw_arc_poison_dw() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.write_downgrade |write_mode| {
                 do (&write_mode).write |one| {
@@ -613,7 +613,7 @@ pub fn test_rw_arc_poison_dw() {
     #[test] #[ignore(cfg(windows))]
     pub fn test_rw_arc_no_poison_rr() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.read |one| {
                 fail_unless!(*one == 2);
@@ -626,7 +626,7 @@ pub fn test_rw_arc_no_poison_rr() {
     #[test] #[ignore(cfg(windows))]
     pub fn test_rw_arc_no_poison_rw() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.read |one| {
                 fail_unless!(*one == 2);
@@ -639,7 +639,7 @@ pub fn test_rw_arc_no_poison_rw() {
     #[test] #[ignore(cfg(windows))]
     pub fn test_rw_arc_no_poison_dr() {
         let arc = ~RWARC(1);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         do task::try || {
             do arc2.write_downgrade |write_mode| {
                 let read_mode = arc2.downgrade(write_mode);
@@ -655,7 +655,7 @@ pub fn test_rw_arc_no_poison_dr() {
     #[test]
     pub fn test_rw_arc() {
         let arc = ~RWARC(0);
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         let (p,c) = comm::stream();
 
         do task::spawn || {
@@ -673,7 +673,7 @@ pub fn test_rw_arc() {
         // Readers try to catch the writer in the act
         let mut children = ~[];
         for 5.times {
-            let arc3 = ~arc.clone();
+            let arc3 = (*arc).clone();
             do task::task().future_result(|+r| children.push(r)).spawn
                 || {
                 do arc3.read |num| {
@@ -704,7 +704,7 @@ pub fn test_rw_downgrade() {
         for 10.times {
             let ((rp1,rc1),(rp2,rc2)) = (comm::stream(),comm::stream());
             reader_convos.push((rc1, rp2));
-            let arcn = ~arc.clone();
+            let arcn = (*arc).clone();
             do task::spawn || {
                 rp1.recv(); // wait for downgrader to give go-ahead
                 do arcn.read |state| {
@@ -715,7 +715,7 @@ pub fn test_rw_downgrade() {
         }
 
         // Writer task
-        let arc2 = ~arc.clone();
+        let arc2 = (*arc).clone();
         let ((wp1,wc1),(wp2,wc2)) = (comm::stream(),comm::stream());
         do task::spawn || {
             wp1.recv();
index abd8bc742359c0cf3a8cfca5c2901d86f92b1fda..1d1ec0e11f7fa0fe689b6381d7a5f53239845f30 100644 (file)
@@ -827,7 +827,7 @@ pub fn test_mutex_lock() {
         // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance.
         let (p,c) = comm::stream();
         let m = ~Mutex();
-        let m2 = ~m.clone();
+        let m2 = m.clone();
         let mut sharedstate = ~0;
         let ptr = ptr::addr_of(&(*sharedstate));
         do task::spawn || {
@@ -1105,13 +1105,13 @@ pub fn test_rwlock_exclusion(x: ~RWlock,
         // Test mutual exclusion between readers and writers. Just like the
         // mutex mutual exclusion test, a ways above.
         let (p,c) = comm::stream();
-        let x2 = ~x.clone();
+        let x2 = (*x).clone();
         let mut sharedstate = ~0;
         let ptr = ptr::addr_of(&(*sharedstate));
         do task::spawn || {
             let sharedstate: &mut int =
                 unsafe { cast::reinterpret_cast(&ptr) };
-            access_shared(sharedstate, x2, mode1, 10);
+            access_shared(sharedstate, &x2, mode1, 10);
             c.send(());
         }
         access_shared(sharedstate, x, mode2, 10);
@@ -1150,14 +1150,14 @@ pub fn test_rwlock_handshake(x: ~RWlock,
                                  mode2: RWlockMode,
                                  make_mode2_go_first: bool) {
         // Much like sem_multi_resource.
-        let x2 = ~x.clone();
+        let x2 = (*x).clone();
         let (p1,c1) = comm::stream();
         let (p2,c2) = comm::stream();
         do task::spawn || {
             if !make_mode2_go_first {
                 let _ = p2.recv(); // parent sends to us once it locks, or ...
             }
-            do lock_rwlock_in_mode(x2, mode2) {
+            do lock_rwlock_in_mode(&x2, mode2) {
                 if make_mode2_go_first {
                     c1.send(()); // ... we send to it once we lock
                 }
@@ -1207,7 +1207,7 @@ pub fn test_rwlock_cond_wait() {
 
         // Child wakes up parent
         do x.write_cond |cond| {
-            let x2 = ~x.clone();
+            let x2 = (*x).clone();
             do task::spawn || {
                 do x2.write_cond |cond| {
                     let woken = cond.signal();
@@ -1218,7 +1218,7 @@ pub fn test_rwlock_cond_wait() {
         }
         // Parent wakes up child
         let (port,chan) = comm::stream();
-        let x3 = ~x.clone();
+        let x3 = (*x).clone();
         do task::spawn || {
             do x3.write_cond |cond| {
                 chan.send(());
@@ -1253,11 +1253,11 @@ fn lock_cond(x: &RWlock, downgrade: bool, blk: &fn(c: &Condvar)) {
         let mut ports = ~[];
 
         for num_waiters.times {
-            let xi = ~x.clone();
+            let xi = (*x).clone();
             let (port, chan) = comm::stream();
             ports.push(port);
             do task::spawn || {
-                do lock_cond(xi, dg1) |cond| {
+                do lock_cond(&xi, dg1) |cond| {
                     chan.send(());
                     cond.wait();
                     chan.send(());
@@ -1289,10 +1289,10 @@ pub fn test_rwlock_cond_broadcast() {
     pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) {
         // Mutex must get automatically unlocked if failed/killed within.
         let x = ~RWlock();
-        let x2 = ~x.clone();
+        let x2 = (*x).clone();
 
         let result: result::Result<(),()> = do task::try || {
-            do lock_rwlock_in_mode(x2, mode1) {
+            do lock_rwlock_in_mode(&x2, mode1) {
                 fail!();
             }
         };
index 97f2e516603beb7e040c246653f131f6ee455b73..15ba7f95538fa478da763b01b6e04bf0175b7524 100644 (file)
@@ -63,7 +63,7 @@ pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
         debug!("colive iteration %?", i);
         let mut new_colive = ~[];
         for colive.eachi |i, this_colive| {
-            let mut result = ~this_colive.clone();
+            let mut result = this_colive.clone();
             let this = proto.get_state_by_id(i);
             for this_colive.ones |j| {
                 let next = proto.get_state_by_id(j);