Merge pull request #3706 from erickt/str-with-capacity

libcore: add a str::with_capacity to match the fn in vec
This commit is contained in:
Tim Chevalier 2012-10-17 11:03:58 -07:00
commit ebce09702f

View File

@ -1473,6 +1473,11 @@ pub pure fn from_utf16(v: &[u16]) -> ~str {
move buf
}
pub pure fn with_capacity(capacity: uint) -> ~str {
let mut buf = ~"";
unsafe { reserve(&mut buf, capacity); }
move buf
}
/**
* As char_len but for a slice of a string