refactor: remove leftover from read_initializer feature (#2949)

This commit is contained in:
Paolo Barbolini
2025-04-16 14:03:16 +02:00
committed by GitHub
parent 142fdcbded
commit 215d4111b8
2 changed files with 6 additions and 15 deletions

View File

@@ -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;

View File

@@ -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..];