Skip to content

Commit dfe46f7

Browse files
committed
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.
2 parents 9bf62f7 + be6ae6e commit dfe46f7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libstd/io/mem.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ pub struct MemWriter {
2727
}
2828

2929
impl MemWriter {
30+
/// Create a new `MemWriter`.
3031
pub fn new() -> MemWriter {
31-
MemWriter { buf: vec::with_capacity(128), pos: 0 }
32+
MemWriter::with_capacity(128)
33+
}
34+
/// Create a new `MemWriter`, allocating at least `n` bytes for
35+
/// the internal buffer.
36+
pub fn with_capacity(n: uint) -> MemWriter {
37+
MemWriter { buf: vec::with_capacity(n), pos: 0 }
3238
}
3339
}
3440

0 commit comments

Comments
 (0)