Avoid unnecessary Vec construction in BufReader
This commit is contained in:
parent
939b14334d
commit
9425e304b1
2 changed files with 4 additions and 4 deletions
|
@ -90,10 +90,9 @@ impl<R: Read> BufReader<R> {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn with_capacity(capacity: usize, inner: R) -> BufReader<R> {
|
||||
unsafe {
|
||||
let mut buffer = Vec::with_capacity(capacity);
|
||||
buffer.set_len(capacity);
|
||||
inner.initializer().initialize(&mut buffer);
|
||||
BufReader { inner, buf: buffer.into_boxed_slice(), pos: 0, cap: 0 }
|
||||
let mut buf = Box::new_uninit_slice(capacity).assume_init();
|
||||
inner.initializer().initialize(&mut buf);
|
||||
BufReader { inner, buf, pos: 0, cap: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,7 @@
|
|||
#![feature(needs_panic_runtime)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(never_type)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(nll)]
|
||||
#![feature(nonnull_slice_from_raw_parts)]
|
||||
#![feature(once_cell)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue