Skip to content

Commit 215d411

Browse files
refactor: remove leftover from read_initializer feature (#2949)
1 parent 142fdcb commit 215d411

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

futures-util/src/io/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use crate::compat::Compat;
2222
use crate::future::assert_future;
2323
use crate::stream::assert_stream;
24-
use std::{pin::Pin, ptr, string::String, vec::Vec};
24+
use std::{pin::Pin, string::String, vec::Vec};
2525

2626
// Re-export some types from `std::io` so that users don't have to deal
2727
// with conflicts when `use`ing `futures::io` and `std::io`.
@@ -34,14 +34,6 @@ pub use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};
3434
// https://github.com/rust-lang/rust/blob/master/src/libstd/sys_common/io.rs#L1
3535
const DEFAULT_BUF_SIZE: usize = 8 * 1024;
3636

37-
/// Initializes a buffer if necessary.
38-
///
39-
/// A buffer is currently always initialized.
40-
#[inline]
41-
unsafe fn initialize<R: AsyncRead>(_reader: &R, buf: &mut [u8]) {
42-
unsafe { ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len()) }
43-
}
44-
4537
mod allow_std;
4638
pub use self::allow_std::AllowStdIo;
4739

futures-util/src/io/read_to_end.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use futures_core::ready;
33
use futures_core::task::{Context, Poll};
44
use futures_io::AsyncRead;
55
use std::io;
6+
use std::iter;
67
use std::pin::Pin;
78
use std::vec::Vec;
89

@@ -55,12 +56,10 @@ pub(super) fn read_to_end_internal<R: AsyncRead + ?Sized>(
5556
let mut g = Guard { len: buf.len(), buf };
5657
loop {
5758
if g.len == g.buf.len() {
58-
unsafe {
59-
g.buf.reserve(32);
60-
let capacity = g.buf.capacity();
61-
g.buf.set_len(capacity);
62-
super::initialize(&rd, &mut g.buf[g.len..]);
63-
}
59+
g.buf.reserve(32);
60+
let spare_capacity = g.buf.capacity() - g.buf.len();
61+
// FIXME: switch to `Vec::resize` once rust-lang/rust#120050 is fixed
62+
g.buf.extend(iter::repeat(0).take(spare_capacity));
6463
}
6564

6665
let buf = &mut g.buf[g.len..];

0 commit comments

Comments
 (0)