about summary refs log tree commit diff
path: root/src/libcore/dvec.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-08-13 15:06:13 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-08-20 22:00:06 -0700
commit8ee79c79aada1b5943b5ada11570f9b903c74579 (patch)
treece1c9def7d1a4a032c64bc2e78e643b2a40bf0d0 /src/libcore/dvec.rs
parent3b09c3deaa9a376d0ae40a783713ece3720ca08f (diff)
new region inference, seperate infer into modules, improve error msgs
Fixes #2806
Fixes #3197
Fixes #3138
Diffstat (limited to 'src/libcore/dvec.rs')
-rw-r--r--src/libcore/dvec.rs35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs
index ecbff6f12df..1c50e948185 100644
--- a/src/libcore/dvec.rs
+++ b/src/libcore/dvec.rs
@@ -90,7 +90,7 @@ priv impl<A> DVec<A> {
     }
 
     #[inline(always)]
-    fn borrow<B>(f: fn(-~[mut A]) -> B) -> B {
+    fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
         unsafe {
             let mut data = unsafe::reinterpret_cast(null::<()>());
             data <-> self.data;
@@ -124,13 +124,13 @@ impl<A> DVec<A> {
      */
     #[inline(always)]
     fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
-        self.borrow(|v| self.give_back(f(v)))
+        self.check_out(|v| self.give_back(f(v)))
     }
 
     /// Returns the number of elements currently in the dvec
     pure fn len() -> uint {
         unchecked {
-            do self.borrow |v| {
+            do self.check_out |v| {
                 let l = v.len();
                 self.give_back(v);
                 l
@@ -146,7 +146,7 @@ impl<A> DVec<A> {
 
     /// Remove and return the last element
     fn pop() -> A {
-        do self.borrow |v| {
+        do self.check_out |v| {
             let mut v <- v;
             let result = vec::pop(v);
             self.give_back(v);
@@ -176,7 +176,7 @@ impl<A> DVec<A> {
 
     /// Remove and return the first element
     fn shift() -> A {
-        do self.borrow |v| {
+        do self.check_out |v| {
             let mut v = vec::from_mut(v);
             let result = vec::shift(v);
             self.give_back(vec::to_mut(v));
@@ -184,10 +184,29 @@ impl<A> DVec<A> {
         }
     }
 
-    // Reverse the elements in the list, in place
+    /// Reverse the elements in the list, in place
     fn reverse() {
-        do self.borrow |v| {
+        do self.check_out |v| {
             vec::reverse(v);
+            self.give_back(v);
+        }
+    }
+
+    /// Gives access to the vector as a slice with immutable contents
+    fn borrow<R>(op: fn(x: &[A]) -> R) -> R {
+        do self.check_out |v| {
+            let result = op(v);
+            self.give_back(v);
+            result
+        }
+    }
+
+    /// Gives access to the vector as a slice with mutable contents
+    fn borrow_mut<R>(op: fn(x: &[mut A]) -> R) -> R {
+        do self.check_out |v| {
+            let result = op(v);
+            self.give_back(v);
+            result
         }
     }
 }
@@ -249,7 +268,7 @@ impl<A: copy> DVec<A> {
      */
     pure fn get() -> ~[A] {
         unchecked {
-            do self.borrow |v| {
+            do self.check_out |v| {
                 let w = vec::from_mut(copy v);
                 self.give_back(v);
                 w