Add specializations of read_to_end for Stdin, TcpStream and File,
allowing them to read into a buffer containing uninitialized data, rather than pay the cost of zeroing.
This commit is contained in:
parent
e4e93196e1
commit
98f287240f
6 changed files with 166 additions and 0 deletions
|
@ -25,6 +25,7 @@ use io::{self, SeekFrom, Seek, Read, Write};
|
|||
use path::{Path, PathBuf};
|
||||
use sys::fs as fs_imp;
|
||||
use sys_common::{AsInnerMut, FromInner, AsInner};
|
||||
use sys_common::io::read_to_end_uninitialized;
|
||||
use vec::Vec;
|
||||
|
||||
/// A reference to an open file on the filesystem.
|
||||
|
@ -328,6 +329,9 @@ impl Read for File {
|
|||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.inner.read(buf)
|
||||
}
|
||||
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
|
||||
unsafe { read_to_end_uninitialized(self, buf) }
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Write for File {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue