about summary refs log tree commit diff
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2012-10-09 08:36:06 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2012-10-09 08:52:46 -0700
commitbdc1b7a8a71b0168a26e1f897246abc6c6ab1091 (patch)
tree910a07ab0084a3930bb8e53f7f0990686687da9c
parent22efa39382d41b084fde1719df7ae8ce5697d8c9 (diff)
downloadrust-bdc1b7a8a71b0168a26e1f897246abc6c6ab1091.tar.gz
rust-bdc1b7a8a71b0168a26e1f897246abc6c6ab1091.zip
libcore: add a str::with_capacity to match the fn in vec
-rw-r--r--src/libcore/str.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index d743f0c7f3b..33016bf9923 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