Skip to content

Commit 50c4506

Browse files
committed
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.
1 parent 8f39dba commit 50c4506

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/liballoc/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ impl<T> Vec<T> {
840840

841841
// space for the new element
842842
if len == self.buf.cap() {
843-
self.buf.double();
843+
self.reserve(1);
844844
}
845845

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

0 commit comments

Comments
 (0)