diff options
author | Guanhao Yin <sopium@mysterious.site> | 2017-03-28 12:33:50 +0800 |
---|---|---|
committer | Guanhao Yin <sopium@mysterious.site> | 2017-03-28 12:33:50 +0800 |
commit | 68d2f0f71636c74232f3280a72622c2c5b7fb5d9 (patch) | |
tree | 37e9a165b5960b703d141963c27341b04782df0e | |
parent | Use less hard coded lengths and slice indexes (diff) | |
download | wireguard-rs-68d2f0f71636c74232f3280a72622c2c5b7fb5d9.tar.xz wireguard-rs-68d2f0f71636c74232f3280a72622c2c5b7fb5d9.zip |
Allocate the queue with enough capacity
-rw-r--r-- | src/protocol/controller.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/protocol/controller.rs b/src/protocol/controller.rs index b0d284b..0b54343 100644 --- a/src/protocol/controller.rs +++ b/src/protocol/controller.rs @@ -785,7 +785,7 @@ pub fn wg_add_peer(wg: Arc<WgState>, peer: &PeerInfo, sock: Arc<UdpSocket>) { handshake: None, rx_bytes: AtomicU64::new(0), tx_bytes: AtomicU64::new(0), - queue: Mutex::new(VecDeque::new()), + queue: Mutex::new(VecDeque::with_capacity(QUEUE_SIZE)), transport0: None, transport1: None, transport2: None, @@ -1068,7 +1068,7 @@ impl PeerState { fn dequeue_all(&self) -> VecDeque<Vec<u8>> { let mut queue = self.queue.lock().unwrap(); - let mut out = VecDeque::new(); + let mut out = VecDeque::with_capacity(QUEUE_SIZE); ::std::mem::swap(&mut out, &mut queue); out } |