io: remove zeroing for AsyncRead implementors (#2525)

This commit is contained in:
Mikail Bagishov 2020-05-21 20:42:28 +03:00 committed by GitHub
parent 4f4f4807c3
commit 1e54a35325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 1 deletions

View File

@ -537,6 +537,11 @@ impl File {
}
impl AsyncRead for File {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
// https://github.com/rust-lang/rust/blob/09c817eeb29e764cfc12d0a8d94841e3ffe34023/src/libstd/fs.rs#L668
false
}
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,

View File

@ -76,7 +76,7 @@ pub trait AsyncRead {
/// [`poll_read_buf`]: #method.poll_read_buf
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
for x in buf {
*x.as_mut_ptr() = 0;
*x = MaybeUninit::new(0);
}
true

View File

@ -183,6 +183,7 @@ mod async_buf_read;
pub use self::async_buf_read::AsyncBufRead;
mod async_read;
pub use self::async_read::AsyncRead;
mod async_seek;

View File

@ -63,6 +63,11 @@ impl std::os::windows::io::AsRawHandle for Stdin {
}
impl AsyncRead for Stdin {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
// https://github.com/rust-lang/rust/blob/09c817eeb29e764cfc12d0a8d94841e3ffe34023/src/libstd/io/stdio.rs#L97
false
}
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,

View File

@ -84,6 +84,15 @@ where
T: AsyncRead,
U: AsyncRead,
{
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
if self.first.prepare_uninitialized_buffer(buf) {
return true;
}
if self.second.prepare_uninitialized_buffer(buf) {
return true;
}
false
}
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,

View File

@ -47,6 +47,9 @@ cfg_io_util! {
}
impl AsyncRead for Empty {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
false
}
#[inline]
fn poll_read(
self: Pin<&mut Self>,

View File

@ -47,6 +47,9 @@ cfg_io_util! {
}
impl AsyncRead for Repeat {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
false
}
#[inline]
fn poll_read(
self: Pin<&mut Self>,

View File

@ -879,6 +879,11 @@ impl AsyncWrite for ChildStdin {
}
impl AsyncRead for ChildStdout {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
// https://github.com/rust-lang/rust/blob/09c817eeb29e764cfc12d0a8d94841e3ffe34023/src/libstd/process.rs#L314
false
}
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
@ -889,6 +894,11 @@ impl AsyncRead for ChildStdout {
}
impl AsyncRead for ChildStderr {
unsafe fn prepare_uninitialized_buffer(&self, _buf: &mut [std::mem::MaybeUninit<u8>]) -> bool {
// https://github.com/rust-lang/rust/blob/09c817eeb29e764cfc12d0a8d94841e3ffe34023/src/libstd/process.rs#L375
false
}
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,