diff options
| author | bors <bors@rust-lang.org> | 2018-05-21 06:19:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-21 06:19:44 +0000 |
| commit | 98686ca2944db341b0933e341b1e9029a905e322 (patch) | |
| tree | 5bd43305c4efe03c3d1528adad3c47a460626639 /src/liballoc/vec.rs | |
| parent | ba1363ffe12ac1ac796a620aef2008e4ae6c0477 (diff) | |
| parent | 50c4506329673d38b3170f048f546a5885dd8310 (diff) | |
| download | rust-98686ca2944db341b0933e341b1e9029a905e322.tar.gz rust-98686ca2944db341b0933e341b1e9029a905e322.zip | |
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
Diffstat (limited to 'src/liballoc/vec.rs')
| -rw-r--r-- | src/liballoc/vec.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index bf89b377b7e..c48c64a8bef 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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 { @@ -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); |
