diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2021-11-29 21:15:51 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2021-11-30 08:10:47 +1100 |
| commit | 6a83352aa3cb80eb83cb57aba30aad32d3881af7 (patch) | |
| tree | bf25452b8be1008b9f4a5608c1f1e438b61075e3 /library/alloc/src/vec | |
| parent | 686e313a9aa14107c8631ffe48fa09110a7692db (diff) | |
| download | rust-6a83352aa3cb80eb83cb57aba30aad32d3881af7.tar.gz rust-6a83352aa3cb80eb83cb57aba30aad32d3881af7.zip | |
Introduce `RawVec::reserve_for_push`.
If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which then also does a capacity check. This commit introduces `reserve_for_push` which skips the redundant capacity check, for some slight compile time speed-ups. I tried lots of minor variations on this, e.g. different inlining attributes. This was the best one I could find.
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 85759917765..88bde6e8ce4 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1726,7 +1726,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.reserve(1); + self.buf.reserve_for_push(self.len); } unsafe { let end = self.as_mut_ptr().add(self.len); |
