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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user