diff options
| author | Tim Chevalier <catamorphism@gmail.com> | 2012-10-17 11:03:58 -0700 |
|---|---|---|
| committer | Tim Chevalier <catamorphism@gmail.com> | 2012-10-17 11:03:58 -0700 |
| commit | ebce09702f04640a545a41323f2d4a34c0023f9e (patch) | |
| tree | c5e13dec4527873170e5ff430d490308e68e60d3 /src/libcore | |
| parent | 7f12cc4e63657155f54fd734c791f66f5f6d9e20 (diff) | |
| parent | bdc1b7a8a71b0168a26e1f897246abc6c6ab1091 (diff) | |
Merge pull request #3706 from erickt/str-with-capacity
libcore: add a str::with_capacity to match the fn in vec
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/str.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 447cb59acf8..18a8f3d3702 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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 |
