From e11dd06ead68230dde6455367ff3237387e4981e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 11 Feb 2017 10:23:02 +0100 Subject: [PATCH] Assure we don't have to allocate while growing the vector We now have enough capacity to copy the unconsumed portion of the previous frame. --- src/io/frame.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/io/frame.rs b/src/io/frame.rs index 44fa5a1b9..552deb5ec 100644 --- a/src/io/frame.rs +++ b/src/io/frame.rs @@ -1,6 +1,7 @@ use std::fmt; use std::io; use std::mem; +use std::cmp; use std::ops::{Deref, DerefMut}; use std::sync::Arc; @@ -152,7 +153,7 @@ impl EasyBuf { // If we couldn't get access above then we give ourself a new buffer // here. - let mut v = Vec::with_capacity(INITIAL_CAPACITY); + let mut v = Vec::with_capacity(cmp::min(INITIAL_CAPACITY, self.as_ref().len())); v.extend_from_slice(self.as_ref()); self.start = 0; self.buf = Arc::new(v);