Skip to content

Commit

Permalink
auto merge of #10737 : huonw/rust/with-cap, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Nov 30, 2013
2 parents 9bf62f7 + be6ae6e commit dfe46f7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libstd/io/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down

0 comments on commit dfe46f7

Please sign in to comment.