Skip to content

Commit

Permalink
Update library/alloc/src/raw_vec.rs
Browse files Browse the repository at this point in the history
Co-authored-by: scottmcm <scottmcm@users.noreply.github.com>
  • Loading branch information
kornelski and scottmcm authored Oct 20, 2023
1 parent 9a55d7a commit 0191b93
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,14 @@ impl<T, A: Allocator> RawVec<T, A> {

if self.needs_to_grow(len, additional) {
do_reserve_and_handle(self, len, additional);
unsafe {
// Inform the optimizer that the reservation has succeeded
core::intrinsics::assume(!self.needs_to_grow(len, additional));
}
}

// SAFETY: The call to `do_reserve_and_handle` ensured this
// (or it panicked) and thus the addition cannot overflow.
unsafe {
// Inform the optimizer that the reservation has succeeded
let min_cap = len.unchecked_add(additional);
core::intrinsics::assume(self.cap >= min_cap);
}
}

Expand Down

0 comments on commit 0191b93

Please sign in to comment.