Skip to content

Commit 98686ca

Browse files
committed
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
2 parents ba1363f + 50c4506 commit 98686ca

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
@@ -837,7 +837,7 @@ impl<T> Vec<T> {
837837

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

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

0 commit comments

Comments
 (0)