diff options
| author | gnzlbg <gonzalobg88@gmail.com> | 2018-05-14 13:58:28 +0200 |
|---|---|---|
| committer | gnzlbg <gonzalobg88@gmail.com> | 2018-05-14 13:58:28 +0200 |
| commit | 50c4506329673d38b3170f048f546a5885dd8310 (patch) | |
| tree | 7c62848363047e2e1cac7cb78e183cab79297e02 /src/liballoc | |
| parent | 8f39dbae8cdc4418d3f79c719bd91d8b4f09c86b (diff) | |
| download | rust-50c4506329673d38b3170f048f546a5885dd8310.tar.gz rust-50c4506329673d38b3170f048f546a5885dd8310.zip | |
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.
Diffstat (limited to 'src/liballoc')
| -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 690cbcb559b..ffaff20bcc9 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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); |
