]> git.lizzy.rs Git - rust.git/commitdiff
std::vec::raw: convert copy_memory to a method.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 16 Dec 2013 12:35:02 +0000 (23:35 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 16 Dec 2013 21:36:01 +0000 (08:36 +1100)
src/libextra/uuid.rs
src/libstd/vec.rs

index 10c4b8a3e2f4b6f052a06b2e9a2c7e38029dc67f..38a1394d339c4b7d64a7324a289a70cc2d958da8 100644 (file)
@@ -219,9 +219,7 @@ pub fn from_bytes(b: &[u8]) -> Option<Uuid> {
         }
 
         let mut uuid = Uuid{ bytes: [0, .. 16] };
-        unsafe {
-            vec::raw::copy_memory(uuid.bytes, b);
-        }
+        vec::bytes::copy_memory(uuid.bytes, b);
         Some(uuid)
     }
 
index 3a2b7c689552d9751c28ab11e0637432546566c8..ed58185e3b032c6d55760dc4f8c3c7919d26e4fe 100644 (file)
@@ -2060,6 +2060,12 @@ fn mut_split_at(self, mid: uint) -> (&'a mut [T],
      */
     unsafe fn init_elem(self, i: uint, val: T);
 
+    /// Copies data from `src` to `self`
+    ///
+    /// `self` and `src` must not overlap. Fails if `self` is
+    /// shorter than `src`.
+    unsafe fn copy_memory(self, src: &[T]);
+
     /// Similar to `as_imm_buf` but passing a `*mut T`
     fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U;
 }
@@ -2197,6 +2203,16 @@ unsafe fn init_elem(self, i: uint, val: T) {
         })
     }
 
+    #[inline]
+    unsafe fn copy_memory(self, src: &[T]) {
+        self.as_mut_buf(|p_dst, len_dst| {
+            src.as_imm_buf(|p_src, len_src| {
+                assert!(len_dst >= len_src)
+                ptr::copy_memory(p_dst, p_src, len_src)
+            })
+        })
+    }
+
     #[inline]
     fn as_mut_buf<U>(self, f: |*mut T, uint| -> U) -> U {
         let Slice{ data, len } = self.repr();
@@ -2238,7 +2254,7 @@ pub unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T] {
 pub mod raw {
     use cast;
     use ptr;
-    use vec::{with_capacity, ImmutableVector, MutableVector};
+    use vec::{with_capacity, MutableVector};
     use unstable::raw::Slice;
 
     /**
@@ -2288,21 +2304,6 @@ pub unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T] {
         dst
     }
 
-    /**
-      * Copies data from one vector to another.
-      *
-      * Copies `src` to `dst`. The source and destination may overlap.
-      */
-    #[inline]
-    pub unsafe fn copy_memory<T>(dst: &mut [T], src: &[T]) {
-        dst.as_mut_buf(|p_dst, len_dst| {
-            src.as_imm_buf(|p_src, len_src| {
-                assert!(len_dst >= len_src)
-                ptr::copy_memory(p_dst, p_src, len_src)
-            })
-        })
-    }
-
     /**
      * Returns a pointer to first element in slice and adjusts
      * slice so it no longer contains that element. Fails if
@@ -2331,7 +2332,7 @@ pub unsafe fn pop_ptr<T>(slice: &mut Slice<T>) -> *T {
 
 /// Operations on `[u8]`.
 pub mod bytes {
-    use vec::raw;
+    use vec::MutableVector;
     use ptr;
 
     /// A trait for operations on mutable `[u8]`s.
@@ -2358,8 +2359,8 @@ fn set_memory(self, value: u8) {
       */
     #[inline]
     pub fn copy_memory(dst: &mut [u8], src: &[u8]) {
-        // Bound checks are done at vec::raw::copy_memory.
-        unsafe { raw::copy_memory(dst, src) }
+        // Bound checks are done at .copy_memory.
+        unsafe { dst.copy_memory(src) }
     }
 
     /**
@@ -3585,7 +3586,7 @@ fn test_copy_memory_oob() {
         unsafe {
             let mut a = [1, 2, 3, 4];
             let b = [1, 2, 3, 4, 5];
-            raw::copy_memory(a, b);
+            a.copy_memory(b);
         }
     }