From 48ec1e03ce669fb102dc77e6a4000fc7858fa14c Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 1 Dec 2021 13:31:34 +0100 Subject: [PATCH] Initialize buffer upfront to avoid unnecessary copies --- epp-client/src/connection/registry.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/epp-client/src/connection/registry.rs b/epp-client/src/connection/registry.rs index 8729ad9..1c09690 100644 --- a/epp-client/src/connection/registry.rs +++ b/epp-client/src/connection/registry.rs @@ -65,15 +65,12 @@ impl EppConnection { let message_size = buf_size - 4; debug!("{}: Response buffer size: {}", self.registry, message_size); - let mut buf = Vec::with_capacity(4096); - let mut read_buf = vec![0u8; 4096]; - + let mut buf = vec![0; message_size]; let mut read_size: usize = 0; loop { - let read = self.stream.read(&mut read_buf).await?; + let read = self.stream.read(&mut buf[read_size..]).await?; debug!("{}: Read: {} bytes", self.registry, read); - buf.extend_from_slice(&read_buf[0..read]); read_size += read; debug!("{}: Total read: {} bytes", self.registry, read_size);