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.
This commit is contained in:
Sebastian Thiel
2017-02-11 10:23:02 +01:00
parent 5adde38a65
commit e11dd06ead
+2 -1
View File
@@ -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);