Skip to content

Commit 9425e30

Browse files
committed
Avoid unnecessary Vec construction in BufReader
1 parent 939b143 commit 9425e30

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

library/std/src/io/buffered/bufreader.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ impl<R: Read> BufReader<R> {
9090
#[stable(feature = "rust1", since = "1.0.0")]
9191
pub fn with_capacity(capacity: usize, inner: R) -> BufReader<R> {
9292
unsafe {
93-
let mut buffer = Vec::with_capacity(capacity);
94-
buffer.set_len(capacity);
95-
inner.initializer().initialize(&mut buffer);
96-
BufReader { inner, buf: buffer.into_boxed_slice(), pos: 0, cap: 0 }
93+
let mut buf = Box::new_uninit_slice(capacity).assume_init();
94+
inner.initializer().initialize(&mut buf);
95+
BufReader { inner, buf, pos: 0, cap: 0 }
9796
}
9897
}
9998
}

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
#![feature(needs_panic_runtime)]
290290
#![feature(negative_impls)]
291291
#![feature(never_type)]
292+
#![feature(new_uninit)]
292293
#![feature(nll)]
293294
#![feature(nonnull_slice_from_raw_parts)]
294295
#![feature(once_cell)]

0 commit comments

Comments
 (0)