vec: use contains_managed instead of box header

This commit is contained in:
Daniel Micay 2013-06-29 22:40:40 -04:00
parent b91416214e
commit 350a5c0b72

View file

@ -34,7 +34,7 @@ use unstable::intrinsics;
#[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 @@ impl<T> OwnedVector<T> for ~[T] {
}
}
/**
* 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.
*