mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add an optimizer hint for the capacity that with_capacity_in returns
This commit is contained in:
parent
b44b367232
commit
da15248d26
@ -423,7 +423,13 @@ impl<A: Allocator> RawVecInner<A> {
|
||||
#[inline]
|
||||
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self {
|
||||
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc, elem_layout) {
|
||||
Ok(res) => res,
|
||||
Ok(this) => {
|
||||
unsafe {
|
||||
// Make it more obvious that a subsquent Vec::reserve(capacity) will not allocate.
|
||||
hint::assert_unchecked(!this.needs_to_grow(0, capacity, elem_layout));
|
||||
}
|
||||
this
|
||||
}
|
||||
Err(err) => handle_error(err),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user