Skip to content

Commit 350a5c0

Browse files
committed
vec: use contains_managed instead of box header
1 parent b914162 commit 350a5c0

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/libstd/vec.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use unstable::intrinsics;
3434
#[cfg(stage0)]
3535
use intrinsic::{get_tydesc};
3636
#[cfg(not(stage0))]
37-
use unstable::intrinsics::{get_tydesc};
37+
use unstable::intrinsics::{get_tydesc, contains_managed};
3838
use vec;
3939
use util;
4040

@@ -1521,6 +1521,7 @@ impl<T> OwnedVector<T> for ~[T] {
15211521
* * n - The number of elements to reserve space for
15221522
*/
15231523
#[inline]
1524+
#[cfg(stage0)]
15241525
fn reserve(&mut self, n: uint) {
15251526
// Only make the (slow) call into the runtime if we have to
15261527
use managed;
@@ -1538,6 +1539,33 @@ impl<T> OwnedVector<T> for ~[T] {
15381539
}
15391540
}
15401541

1542+
/**
1543+
* Reserves capacity for exactly `n` elements in the given vector.
1544+
*
1545+
* If the capacity for `self` is already equal to or greater than the requested
1546+
* capacity, then no action is taken.
1547+
*
1548+
* # Arguments
1549+
*
1550+
* * n - The number of elements to reserve space for
1551+
*/
1552+
#[inline]
1553+
#[cfg(not(stage0))]
1554+
fn reserve(&mut self, n: uint) {
1555+
// Only make the (slow) call into the runtime if we have to
1556+
if self.capacity() < n {
1557+
unsafe {
1558+
let ptr: **raw::VecRepr = cast::transmute(self);
1559+
let td = get_tydesc::<T>();
1560+
if contains_managed::<T>() {
1561+
rustrt::vec_reserve_shared_actual(td, ptr, n as libc::size_t);
1562+
} else {
1563+
rustrt::vec_reserve_shared(td, ptr, n as libc::size_t);
1564+
}
1565+
}
1566+
}
1567+
}
1568+
15411569
/**
15421570
* Reserves capacity for at least `n` elements in the given vector.
15431571
*

0 commit comments

Comments
 (0)