Auto merge of #50739 - gnzlbg:vec_reserve, r=sfackler

Switch Vec from doubling size on growth to using RawVec's reserve

On growth, Vec does not require to exactly double its size for correctness,
like, for example, VecDeque does.

Using reserve instead better expresses this intent. It also allows to reuse
Excess capacity on growth and for better growth-policies to be provided by
RawVec.

r? @sfackler
This commit is contained in:
bors
2018-05-21 06:19:44 +00:00

View File

@@ -837,7 +837,7 @@ impl<T> Vec<T> {
// space for the new element // space for the new element
if len == self.buf.cap() { if len == self.buf.cap() {
self.buf.double(); self.reserve(1);
} }
unsafe { unsafe {
@@ -1057,7 +1057,7 @@ impl<T> Vec<T> {
// This will panic or abort if we would allocate > isize::MAX bytes // This will panic or abort if we would allocate > isize::MAX bytes
// or if the length increment would overflow for zero-sized types. // or if the length increment would overflow for zero-sized types.
if self.len == self.buf.cap() { if self.len == self.buf.cap() {
self.buf.double(); self.reserve(1);
} }
unsafe { unsafe {
let end = self.as_mut_ptr().offset(self.len as isize); let end = self.as_mut_ptr().offset(self.len as isize);