From 75a8889d28901062164573b5347748086c861d78 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 1 Apr 2020 23:21:27 +0200 Subject: [PATCH] libasync: create TcpSocketBuffers from uninitialized memory --- libasync/src/smoltcp/tcp_stream.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libasync/src/smoltcp/tcp_stream.rs b/libasync/src/smoltcp/tcp_stream.rs index 3d22d4b..d34d5f2 100644 --- a/libasync/src/smoltcp/tcp_stream.rs +++ b/libasync/src/smoltcp/tcp_stream.rs @@ -47,9 +47,15 @@ macro_rules! poll_stream { impl TcpStream { fn new(rx_bufsize: usize, tx_bufsize: usize) -> Self { - // TODO: Uninitialized is faster than zeroed - let rx_buffer = TcpSocketBuffer::new(vec![0u8; rx_bufsize]); - let tx_buffer = TcpSocketBuffer::new(vec![0u8; tx_bufsize]); + fn uninit_vec(size: usize) -> Vec { + let mut result = Vec::with_capacity(size); + unsafe { + result.set_len(size); + } + result + } + let rx_buffer = TcpSocketBuffer::new(uninit_vec(rx_bufsize)); + let tx_buffer = TcpSocketBuffer::new(uninit_vec(tx_bufsize)); let socket = TcpSocket::new(rx_buffer, tx_buffer); let handle = Sockets::instance().sockets.borrow_mut() .add(socket);