Skip to content

Commit

Permalink
Auto merge of #50739 - gnzlbg:vec_reserve, r=sfackler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 21, 2018
2 parents ba1363f + 50c4506 commit 98686ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl<T> Vec<T> {

// space for the new element
if len == self.buf.cap() {
self.buf.double();
self.reserve(1);
}

unsafe {
Expand Down Expand Up @@ -1057,7 +1057,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);
Expand Down

0 comments on commit 98686ca

Please sign in to comment.