io: Simplify BufReader::with_capacity
Use the vec![] macro directly to create a sized, zeroed vector. This should result in a big speedup when creating BufReader, because vec![0; cap] compiles to a memset call, while the previous extend code currently did not.
This commit is contained in:
parent
6ac0ba3c3a
commit
a5cc17adaa
@ -19,7 +19,6 @@ use error;
|
||||
use fmt;
|
||||
use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
|
||||
use ptr;
|
||||
use iter;
|
||||
|
||||
/// Wraps a `Read` and buffers input from it
|
||||
///
|
||||
@ -63,11 +62,9 @@ impl<R: Read> BufReader<R> {
|
||||
/// Creates a new `BufReader` with the specified buffer capacity
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn with_capacity(cap: usize, inner: R) -> BufReader<R> {
|
||||
let mut buf = Vec::with_capacity(cap);
|
||||
buf.extend(iter::repeat(0).take(cap));
|
||||
BufReader {
|
||||
inner: inner,
|
||||
buf: buf,
|
||||
buf: vec![0; cap],
|
||||
pos: 0,
|
||||
cap: 0,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user