Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit b7b66b6cb3aa7b04d611f22d9d0029945e539db1 1 parent c0a9979
@brson brson authored
Showing with 7 additions and 2 deletions.
  1. +3 −1 src/libcore/str.rs
  2. +4 −1 src/libcore/vec.rs
View
4 src/libcore/str.rs
@@ -1504,7 +1504,9 @@ capacity, then no action is taken.
* n - The number of bytes to reserve space for
"]
fn reserve(&s: str, n: uint) {
- rustrt::str_reserve_shared(s, n);
+ if capacity(s) < n {
+ rustrt::str_reserve_shared(s, n);
+ }
}
#[doc = "
View
5 src/libcore/vec.rs
@@ -113,7 +113,10 @@ capacity, then no action is taken.
* n - The number of elements to reserve space for
"]
fn reserve<T>(&v: [const T], n: uint) {
- rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), v, n);
+ // 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 = "
Please sign in to comment.
Something went wrong with that request. Please try again.