Skip to content

Commit

Permalink
Remove len argument from RawVec::reserve_for_push because it's always…
Browse files Browse the repository at this point in the history
… equal to capacity. Also make Vec::insert use reserve_for_push.
  • Loading branch information
caibear committed Mar 28, 2024
1 parent ba52720 commit 18d3908
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2086,10 +2086,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
// Extend or possibly remove this assertion when valid use-cases for growing the
// buffer without it being full emerge
debug_assert!(self.is_full());
let old_cap = self.capacity();
self.buf.reserve_for_push(old_cap);
self.buf.reserve_for_push();
unsafe {
self.handle_capacity_increase(old_cap);
self.handle_capacity_increase(self.capacity());
}
debug_assert!(!self.is_full());
}
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ impl<T, A: Allocator> RawVec<T, A> {
/// oft-instantiated `Vec::push()`, which does its own capacity check.
#[cfg(not(no_global_oom_handling))]
#[inline(never)]
pub fn reserve_for_push(&mut self, len: usize) {
if let Err(err) = self.grow_amortized(len, 1) {
pub fn reserve_for_push(&mut self) {
if let Err(err) = self.grow_amortized(self.cap.0, 1) {
handle_error(err);
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ impl<T, A: Allocator> Vec<T, A> {

// space for the new element
if len == self.buf.capacity() {
self.reserve(1);
self.buf.reserve_for_push();
}

unsafe {
Expand Down Expand Up @@ -1967,7 +1967,7 @@ impl<T, A: Allocator> Vec<T, A> {
// 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.capacity() {
self.buf.reserve_for_push(self.len);
self.buf.reserve_for_push();
}
unsafe {
let end = self.as_mut_ptr().add(self.len);
Expand Down

0 comments on commit 18d3908

Please sign in to comment.