mirror of
https://github.com/rust-lang/futures-rs.git
synced 2026-01-25 03:26:14 +00:00
refactor: remove leftover from read_initializer feature (#2949)
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
use crate::compat::Compat;
|
||||
use crate::future::assert_future;
|
||||
use crate::stream::assert_stream;
|
||||
use std::{pin::Pin, ptr, string::String, vec::Vec};
|
||||
use std::{pin::Pin, string::String, vec::Vec};
|
||||
|
||||
// Re-export some types from `std::io` so that users don't have to deal
|
||||
// with conflicts when `use`ing `futures::io` and `std::io`.
|
||||
@@ -34,14 +34,6 @@ pub use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};
|
||||
// https://github.com/rust-lang/rust/blob/master/src/libstd/sys_common/io.rs#L1
|
||||
const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
||||
|
||||
/// Initializes a buffer if necessary.
|
||||
///
|
||||
/// A buffer is currently always initialized.
|
||||
#[inline]
|
||||
unsafe fn initialize<R: AsyncRead>(_reader: &R, buf: &mut [u8]) {
|
||||
unsafe { ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len()) }
|
||||
}
|
||||
|
||||
mod allow_std;
|
||||
pub use self::allow_std::AllowStdIo;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ use futures_core::ready;
|
||||
use futures_core::task::{Context, Poll};
|
||||
use futures_io::AsyncRead;
|
||||
use std::io;
|
||||
use std::iter;
|
||||
use std::pin::Pin;
|
||||
use std::vec::Vec;
|
||||
|
||||
@@ -55,12 +56,10 @@ pub(super) fn read_to_end_internal<R: AsyncRead + ?Sized>(
|
||||
let mut g = Guard { len: buf.len(), buf };
|
||||
loop {
|
||||
if g.len == g.buf.len() {
|
||||
unsafe {
|
||||
g.buf.reserve(32);
|
||||
let capacity = g.buf.capacity();
|
||||
g.buf.set_len(capacity);
|
||||
super::initialize(&rd, &mut g.buf[g.len..]);
|
||||
}
|
||||
g.buf.reserve(32);
|
||||
let spare_capacity = g.buf.capacity() - g.buf.len();
|
||||
// FIXME: switch to `Vec::resize` once rust-lang/rust#120050 is fixed
|
||||
g.buf.extend(iter::repeat(0).take(spare_capacity));
|
||||
}
|
||||
|
||||
let buf = &mut g.buf[g.len..];
|
||||
|
||||
Reference in New Issue
Block a user