about summary refs log tree commit diff
path: root/library/alloc/src/vec
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-30 00:29:24 +0000
committerbors <bors@rust-lang.org>2024-03-30 00:29:24 +0000
commit877d36b1928b5a4f7d193517b48290ecbe404d71 (patch)
tree55673ca0ab72dc8ff30e308b1d937b7b3e477cf7 /library/alloc/src/vec
parenta3cfa031fa7726a957d73e6cad5744eb9706f56d (diff)
parent4500c83c62e9fe90b9807006bcd809af1ec940b3 (diff)
Auto merge of #122976 - caibear:optimize_reserve_for_push, r=cuviper
Remove len argument from RawVec::reserve_for_push

Removes `RawVec::reserve_for_push`'s `len` argument since it's always the same as capacity.
Also makes `Vec::insert` use `RawVec::reserve_for_push`.
Diffstat (limited to 'library/alloc/src/vec')
-rw-r--r--library/alloc/src/vec/mod.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs
index 8ca8046dac5..7e3463bc082 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.grow_one();
         }
 
         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.grow_one();
         }
         unsafe {
             let end = self.as_mut_ptr().add(self.len);