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.
This commit is contained in:
bors 2013-11-30 09:56:41 -08:00
commit dfe46f788b

View File

@ -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 }
}
}