]> git.lizzy.rs Git - rust.git/commitdiff
vec: use contains_managed instead of box header
authorDaniel Micay <danielmicay@gmail.com>
Sun, 30 Jun 2013 02:40:40 +0000 (22:40 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Sun, 30 Jun 2013 07:45:39 +0000 (03:45 -0400)
src/libstd/vec.rs

index 4196fbac0beb5a7bc391784364858dc75d09f54d..009c84a4a6e9fa9980cdadcb7e881c99b15d2fcb 100644 (file)
@@ -34,7 +34,7 @@
 #[cfg(stage0)]
 use intrinsic::{get_tydesc};
 #[cfg(not(stage0))]
-use unstable::intrinsics::{get_tydesc};
+use unstable::intrinsics::{get_tydesc, contains_managed};
 use vec;
 use util;
 
@@ -1521,6 +1521,7 @@ impl<T> OwnedVector<T> for ~[T] {
      * * n - The number of elements to reserve space for
      */
     #[inline]
+    #[cfg(stage0)]
     fn reserve(&mut self, n: uint) {
         // Only make the (slow) call into the runtime if we have to
         use managed;
@@ -1538,6 +1539,33 @@ fn reserve(&mut self, n: uint) {
         }
     }
 
+    /**
+     * Reserves capacity for exactly `n` elements in the given vector.
+     *
+     * If the capacity for `self` is already equal to or greater than the requested
+     * capacity, then no action is taken.
+     *
+     * # Arguments
+     *
+     * * n - The number of elements to reserve space for
+     */
+    #[inline]
+    #[cfg(not(stage0))]
+    fn reserve(&mut self, n: uint) {
+        // Only make the (slow) call into the runtime if we have to
+        if self.capacity() < n {
+            unsafe {
+                let ptr: **raw::VecRepr = cast::transmute(self);
+                let td = get_tydesc::<T>();
+                if contains_managed::<T>() {
+                    rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t);
+                } else {
+                    rustrt::vec_reserve_shared(td, ptr, n as libc::size_t);
+                }
+            }
+        }
+    }
+
     /**
      * Reserves capacity for at least `n` elements in the given vector.
      *