about summary refs log tree commit diff
path: root/src/libstd/vec.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/vec.rs')
-rw-r--r--src/libstd/vec.rs48
1 files changed, 10 insertions, 38 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 65be214c14e..08ab6732aec 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -775,7 +775,7 @@ impl<'a, T> Container for &'a [T] {
     /// Returns the length of a vector
     #[inline]
     fn len(&self) -> uint {
-        self.as_imm_buf(|_p, len| len)
+        self.repr().len
     }
 }
 
@@ -783,7 +783,7 @@ impl<T> Container for ~[T] {
     /// Returns the length of a vector
     #[inline]
     fn len(&self) -> uint {
-        self.as_imm_buf(|_p, len| len)
+        self.repr().len
     }
 }
 
@@ -985,14 +985,6 @@ pub trait ImmutableVector<'a, T> {
     fn map<U>(&self, |t: &T| -> U) -> ~[U];
 
     /**
-     * Work with the buffer of a vector.
-     *
-     * Allows for unsafe manipulation of vector contents, which is useful for
-     * foreign interop.
-     */
-    fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U;
-
-    /**
      * Returns a mutable reference to the first element in this slice
      * and adjusts the slice in place so that it no longer contains
      * that element. O(1).
@@ -1032,14 +1024,12 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
     fn slice(&self, start: uint, end: uint) -> &'a [T] {
         assert!(start <= end);
         assert!(end <= self.len());
-        self.as_imm_buf(|p, _len| {
-            unsafe {
-                cast::transmute(Slice {
-                    data: ptr::offset(p, start as int),
+        unsafe {
+            cast::transmute(Slice {
+                    data: self.as_ptr().offset(start as int),
                     len: (end - start)
                 })
-            }
-        })
+        }
     }
 
     #[inline]
@@ -1197,12 +1187,6 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
         self.iter().map(f).collect()
     }
 
-    #[inline]
-    fn as_imm_buf<U>(&self, f: |*T, uint| -> U) -> U {
-        let s = self.repr();
-        f(s.data, s.len)
-    }
-
     fn shift_ref(&mut self) -> &'a T {
         unsafe {
             let s: &mut Slice<T> = cast::transmute(self);
@@ -2206,10 +2190,9 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [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_nonoverlapping_memory(p_dst, p_src, len_src)
-            })
+            let len_src = src.len();
+            assert!(len_dst >= len_src);
+            ptr::copy_nonoverlapping_memory(p_dst, src.as_ptr(), len_src)
         })
     }
 
@@ -2369,9 +2352,7 @@ pub mod bytes {
         dst.reserve_additional(src.len());
         unsafe {
             dst.as_mut_buf(|p_dst, len_dst| {
-                src.as_imm_buf(|p_src, len_src| {
-                    ptr::copy_memory(p_dst.offset(len_dst as int), p_src, len_src)
-                })
+                ptr::copy_memory(p_dst.offset(len_dst as int), src.as_ptr(), src.len())
             });
             dst.set_len(old_len + src.len());
         }
@@ -3555,15 +3536,6 @@ mod tests {
 
     #[test]
     #[should_fail]
-    fn test_as_imm_buf_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        v.as_imm_buf(|_buf, _i| {
-            fail!()
-        })
-    }
-
-    #[test]
-    #[should_fail]
     fn test_as_mut_buf_fail() {
         let mut v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
         v.as_mut_buf(|_buf, _i| {