Skip to content

Commit

Permalink
Add an optimizer hint for the capacity that with_capacity_in returns
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Aug 10, 2024
1 parent b44b367 commit da15248
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down

0 comments on commit da15248

Please sign in to comment.