1
Fork 0

core: Don't call into the runtime to reserve if we have capacity

This commit is contained in:
Brian Anderson 2012-03-28 23:18:36 -07:00
parent c0a99790cb
commit b7b66b6cb3
2 changed files with 7 additions and 2 deletions

View file

@ -1504,8 +1504,10 @@ capacity, then no action is taken.
* n - The number of bytes to reserve space for
"]
fn reserve(&s: str, n: uint) {
if capacity(s) < n {
rustrt::str_reserve_shared(s, n);
}
}
#[doc = "
Reserves capacity for at least `n` bytes in the given string, not including

View file

@ -113,8 +113,11 @@ capacity, then no action is taken.
* n - The number of elements to reserve space for
"]
fn reserve<T>(&v: [const T], n: uint) {
// Only make the (slow) call into the runtime if we have to
if capacity(v) < n {
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), v, n);
}
}
#[doc = "
Reserves capacity for at least `n` elements in the given vector.