Skip to content

Commit 8e76b15

Browse files
committed
Remove slice_to_end
1 parent 57937d7 commit 8e76b15

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

std/src/sys/pal/windows/handle.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,21 @@ impl Handle {
138138

139139
pub unsafe fn read_overlapped(
140140
&self,
141-
buf: &mut [u8],
141+
buf: &mut [mem::MaybeUninit<u8>],
142142
overlapped: *mut c::OVERLAPPED,
143143
) -> io::Result<Option<usize>> {
144144
// SAFETY: We have exclusive access to the buffer and it's up to the caller to
145145
// ensure the OVERLAPPED pointer is valid for the lifetime of this function.
146146
unsafe {
147147
let len = cmp::min(buf.len(), u32::MAX as usize) as u32;
148148
let mut amt = 0;
149-
let res =
150-
cvt(c::ReadFile(self.as_raw_handle(), buf.as_mut_ptr(), len, &mut amt, overlapped));
149+
let res = cvt(c::ReadFile(
150+
self.as_raw_handle(),
151+
buf.as_mut_ptr().cast::<u8>(),
152+
len,
153+
&mut amt,
154+
overlapped,
155+
));
151156
match res {
152157
Ok(_) => Ok(Some(amt as usize)),
153158
Err(e) => {

std/src/sys/pal/windows/pipe.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read};
55
use crate::mem;
66
use crate::path::Path;
77
use crate::ptr;
8-
use crate::slice;
98
use crate::sync::atomic::AtomicUsize;
109
use crate::sync::atomic::Ordering::Relaxed;
1110
use crate::sys::c;
@@ -479,8 +478,11 @@ impl<'a> AsyncPipe<'a> {
479478
fn schedule_read(&mut self) -> io::Result<bool> {
480479
assert_eq!(self.state, State::NotReading);
481480
let amt = unsafe {
482-
let slice = slice_to_end(self.dst);
483-
self.pipe.read_overlapped(slice, &mut *self.overlapped)?
481+
if self.dst.capacity() == self.dst.len() {
482+
let additional = if self.dst.capacity() == 0 { 16 } else { 1 };
483+
self.dst.reserve(additional);
484+
}
485+
self.pipe.read_overlapped(self.dst.spare_capacity_mut(), &mut *self.overlapped)?
484486
};
485487

486488
// If this read finished immediately then our overlapped event will
@@ -560,15 +562,3 @@ impl<'a> Drop for AsyncPipe<'a> {
560562
}
561563
}
562564
}
563-
564-
#[allow(unsafe_op_in_unsafe_fn)]
565-
unsafe fn slice_to_end(v: &mut Vec<u8>) -> &mut [u8] {
566-
if v.capacity() == 0 {
567-
v.reserve(16);
568-
}
569-
if v.capacity() == v.len() {
570-
v.reserve(1);
571-
}
572-
// FIXME: Isn't this just spare_capacity_mut but worse?
573-
slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len())
574-
}

0 commit comments

Comments
 (0)