summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorAlisdair Owens <awo101@zepler.net>2015-07-10 17:34:07 +0100
committerAlisdair Owens <awo101@zepler.net>2015-07-15 21:30:18 +0100
commit98f287240ff9518c1ea5519c5cd03dc2ba6d4452 (patch)
treeccf70108ba915d7280d99035f647a663ae0c1711 /src/libstd/net
parente4e93196e16030ebf7a20c473849534235d676f8 (diff)
downloadrust-98f287240ff9518c1ea5519c5cd03dc2ba6d4452.tar.gz
rust-98f287240ff9518c1ea5519c5cd03dc2ba6d4452.zip
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.
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/tcp.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs
index 085ba286dc3..66c8403b268 100644
--- a/src/libstd/net/tcp.rs
+++ b/src/libstd/net/tcp.rs
@@ -19,6 +19,7 @@ use io;
 use net::{ToSocketAddrs, SocketAddr, Shutdown};
 use sys_common::net as net_imp;
 use sys_common::{AsInner, FromInner};
+use sys_common::io::read_to_end_uninitialized;
 use time::Duration;
 
 /// A structure which represents a TCP stream between a local socket and a
@@ -189,6 +190,9 @@ impl TcpStream {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Read for TcpStream {
     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.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 TcpStream {
@@ -198,6 +202,9 @@ impl Write for TcpStream {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a> Read for &'a TcpStream {
     fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.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<'a> Write for &'a TcpStream {