File tree 2 files changed +4
-5
lines changed
2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -180,9 +180,7 @@ impl<'self, S: Str> StrVector for &'self [S] {
180
180
181
181
let len = self . iter( ) . transform( |s| s. as_slice( ) . len( ) ) . sum( ) ;
182
182
183
- let mut s = ~"";
184
-
185
- s. reserve( len) ;
183
+ let mut s = with_capacity( len) ;
186
184
187
185
unsafe {
188
186
do s. as_mut_buf |buf, _| {
@@ -678,6 +676,7 @@ pub fn from_utf16(v: &[u16]) -> ~str {
678
676
* Allocates a new string with the specified capacity. The string returned is
679
677
* the empty string, but has capacity for much more.
680
678
*/
679
+ #[ inline]
681
680
pub fn with_capacity ( capacity : uint ) -> ~str {
682
681
let mut buf = ~"";
683
682
buf. reserve ( capacity) ;
@@ -1830,10 +1829,9 @@ impl<'self> StrSlice<'self> for &'self str {
1830
1829
/// Given a string, make a new string with repeated copies of it.
1831
1830
fn repeat(&self, nn: uint) -> ~str {
1832
1831
do self.as_imm_buf |buf, len| {
1833
- let mut ret = ~" ";
1834
1832
// ignore the NULL terminator
1835
1833
let len = len - 1;
1836
- ret.reserve (nn * len);
1834
+ let mut ret = with_capacity (nn * len);
1837
1835
1838
1836
unsafe {
1839
1837
do ret.as_mut_buf |rbuf, _len| {
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> ~[T] {
87
87
}
88
88
89
89
/// Creates a new vector with a capacity of `capacity`
90
+ #[ inline]
90
91
pub fn with_capacity < T > ( capacity : uint ) -> ~[ T ] {
91
92
unsafe {
92
93
if contains_managed :: < T > ( ) {
You can’t perform that action at this time.
0 commit comments