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.
This commit is contained in:
gnzlbg 2018-05-14 13:58:28 +02:00
parent 8f39dbae8c
commit 50c4506329

View File

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