about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-30 09:56:41 -0800
committerbors <bors@rust-lang.org>2013-11-30 09:56:41 -0800
commitdfe46f788bd080fed67c63e7a04dad10468502b3 (patch)
treec7e9e8d05aab68eeafa023e764322777b742bbdb /src/libstd
parent9bf62f71bc5e1844a2b63a77c2c0b4c1d67faf91 (diff)
parentbe6ae6eb373551936fffe83ebe085e4819ab00c0 (diff)
downloadrust-dfe46f788bd080fed67c63e7a04dad10468502b3.tar.gz
rust-dfe46f788bd080fed67c63e7a04dad10468502b3.zip
auto merge of #10737 : huonw/rust/with-cap, r=alexcrichton
This allows one to reduce the number of reallocs of the internal buffer
if one has an approximate idea of the size of the final output.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/mem.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs
index b08f4af9a54..aa3eb9a8317 100644
--- a/src/libstd/io/mem.rs
+++ b/src/libstd/io/mem.rs
@@ -27,8 +27,14 @@ pub struct MemWriter {
 }
 
 impl MemWriter {
+    /// Create a new `MemWriter`.
     pub fn new() -> MemWriter {
-        MemWriter { buf: vec::with_capacity(128), pos: 0 }
+        MemWriter::with_capacity(128)
+    }
+    /// Create a new `MemWriter`, allocating at least `n` bytes for
+    /// the internal buffer.
+    pub fn with_capacity(n: uint) -> MemWriter {
+        MemWriter { buf: vec::with_capacity(n), pos: 0 }
     }
 }