diff options
| author | Cai Bear <git@caibear.com> | 2024-03-23 21:27:59 -0700 |
|---|---|---|
| committer | Cai Bear <git@caibear.com> | 2024-03-28 16:21:54 -0700 |
| commit | 18d390883efc7eaf5ced77d89abc5b51c8b7f816 (patch) | |
| tree | 486fc19f7b562890eb3f8fe8f96877e8e5324c13 /library/alloc/src | |
| parent | ba527200cce74e0b752927f5fd071d06fd9d0962 (diff) | |
| download | rust-18d390883efc7eaf5ced77d89abc5b51c8b7f816.tar.gz rust-18d390883efc7eaf5ced77d89abc5b51c8b7f816.zip | |
Remove len argument from RawVec::reserve_for_push because it's always equal to capacity. Also make Vec::insert use reserve_for_push.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/vec_deque/mod.rs | 5 | ||||
| -rw-r--r-- | library/alloc/src/raw_vec.rs | 4 | ||||
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 4 |
3 files changed, 6 insertions, 7 deletions
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 41adc2e79dc..742daea873e 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -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()); } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 175e23b543c..45258cc86ff 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -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); } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8ca8046dac5..5f4c45d578d 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -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 { @@ -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); |
