Skip to content

Commit

Permalink
Rollup merge of rust-lang#131197 - EFanZh:avoid-emptyness-check-in-pe…
Browse files Browse the repository at this point in the history
…ekmut-pop, r=Amanieu

Avoid emptiness check in `PeekMut::pop`

This PR avoids an unnecessary emptiness check in `PeekMut::pop` by replacing `Option::unwrap` with `Option::unwrap_unchecked`.
  • Loading branch information
matthiaskrgr authored Oct 3, 2024
2 parents 86fa474 + 8cfa0ca commit 1bd16cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion alloc/src/collections/binary_heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> {
// the caller could've mutated the element. It is removed from the
// heap on the next line and pop() is not sensitive to its value.
}
this.heap.pop().unwrap()

// SAFETY: Have a `PeekMut` element proves that the associated binary heap being non-empty,
// so the `pop` operation will not fail.
unsafe { this.heap.pop().unwrap_unchecked() }
}
}

Expand Down

0 comments on commit 1bd16cd

Please sign in to comment.