forked from M-Labs/zynq-rs
1
0
Fork 0

libasync: create TcpSocketBuffers from uninitialized memory

This commit is contained in:
Astro 2020-04-01 23:21:27 +02:00
parent 0618642d3f
commit 75a8889d28
1 changed files with 9 additions and 3 deletions

View File

@ -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<T>(size: usize) -> Vec<T> {
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);