diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-07-23 09:54:28 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-07-23 16:57:00 -0700 |
| commit | bbedbc04507ea3a1e87905c4b37c3460b5de1746 (patch) | |
| tree | 6d6ae7a09477ec8118ac42ba691cb7be5612ba40 /src/libstd | |
| parent | cced3c9013e4f8e1202b6088f9d3b564e40cac40 (diff) | |
| download | rust-bbedbc04507ea3a1e87905c4b37c3460b5de1746.tar.gz rust-bbedbc04507ea3a1e87905c4b37c3460b5de1746.zip | |
std: inline str::with_capacity and vec::with_capacity
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/str.rs | 8 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 1 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b869f574beb..0d2cfa2e1e8 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -180,9 +180,7 @@ impl<'self, S: Str> StrVector for &'self [S] { 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, _| { @@ -678,6 +676,7 @@ pub fn from_utf16(v: &[u16]) -> ~str { * 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); @@ -1830,10 +1829,9 @@ impl<'self> StrSlice<'self> for &'self str { /// 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| { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 6bbf1210a31..cc41f0dbb94 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -87,6 +87,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] { } /// Creates a new vector with a capacity of `capacity` +#[inline] pub fn with_capacity<T>(capacity: uint) -> ~[T] { unsafe { if contains_managed::<T>() { |
