let len = self.iter().transform(|s| s.as_slice().len()).sum();
- let mut s = ~"";
-
- s.reserve(len);
+ let mut s = with_capacity(len);
unsafe {
do s.as_mut_buf |buf, _| {
* Allocates a new string with the specified capacity. The string returned is
* the empty string, but has capacity for much more.
*/
+#[inline]
pub fn with_capacity(capacity: uint) -> ~str {
let mut buf = ~"";
buf.reserve(capacity);
/// Given a string, make a new string with repeated copies of it.
fn repeat(&self, nn: uint) -> ~str {
do self.as_imm_buf |buf, len| {
- let mut ret = ~"";
// ignore the NULL terminator
let len = len - 1;
- ret.reserve(nn * len);
+ let mut ret = with_capacity(nn * len);
unsafe {
do ret.as_mut_buf |rbuf, _len| {
}
/// Creates a new vector with a capacity of `capacity`
+#[inline]
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
unsafe {
if contains_managed::<T>() {