Skip to content

Commit 18d3908

Browse files
committed
Remove len argument from RawVec::reserve_for_push because it's always equal to capacity. Also make Vec::insert use reserve_for_push.
1 parent ba52720 commit 18d3908

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

library/alloc/src/collections/vec_deque/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2086,10 +2086,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
20862086
// Extend or possibly remove this assertion when valid use-cases for growing the
20872087
// buffer without it being full emerge
20882088
debug_assert!(self.is_full());
2089-
let old_cap = self.capacity();
2090-
self.buf.reserve_for_push(old_cap);
2089+
self.buf.reserve_for_push();
20912090
unsafe {
2092-
self.handle_capacity_increase(old_cap);
2091+
self.handle_capacity_increase(self.capacity());
20932092
}
20942093
debug_assert!(!self.is_full());
20952094
}

library/alloc/src/raw_vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl<T, A: Allocator> RawVec<T, A> {
349349
/// oft-instantiated `Vec::push()`, which does its own capacity check.
350350
#[cfg(not(no_global_oom_handling))]
351351
#[inline(never)]
352-
pub fn reserve_for_push(&mut self, len: usize) {
353-
if let Err(err) = self.grow_amortized(len, 1) {
352+
pub fn reserve_for_push(&mut self) {
353+
if let Err(err) = self.grow_amortized(self.cap.0, 1) {
354354
handle_error(err);
355355
}
356356
}

library/alloc/src/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ impl<T, A: Allocator> Vec<T, A> {
15471547

15481548
// space for the new element
15491549
if len == self.buf.capacity() {
1550-
self.reserve(1);
1550+
self.buf.reserve_for_push();
15511551
}
15521552

15531553
unsafe {
@@ -1967,7 +1967,7 @@ impl<T, A: Allocator> Vec<T, A> {
19671967
// This will panic or abort if we would allocate > isize::MAX bytes
19681968
// or if the length increment would overflow for zero-sized types.
19691969
if self.len == self.buf.capacity() {
1970-
self.buf.reserve_for_push(self.len);
1970+
self.buf.reserve_for_push();
19711971
}
19721972
unsafe {
19731973
let end = self.as_mut_ptr().add(self.len);

0 commit comments

Comments
 (0)