diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 20ac62dbac0..d8f0b20062a 100644 --- a/src/libcore/str.rs +++ b/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 = " diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index e4626c97c3e..13c1fccc81a 100644 --- a/src/libcore/vec.rs +++ b/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(&v: [const T], n: uint) { - rustrt::vec_reserve_shared(sys::get_type_desc::(), 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::(), v, n); + } } #[doc = "