diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-03 21:52:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-03 21:52:47 +0200 |
| commit | 29580e12f2eccf7ff8d50999bc82174292532c7d (patch) | |
| tree | 594a4f5bc390c97d0c00e47839b382aabce5ece2 /library/alloc/src | |
| parent | 6753e07d465f619566772906bc63f0e130a4cd41 (diff) | |
| parent | d47e388843f682f57262f020edd9909c850a0c49 (diff) | |
| download | rust-29580e12f2eccf7ff8d50999bc82174292532c7d.tar.gz rust-29580e12f2eccf7ff8d50999bc82174292532c7d.zip | |
Rollup merge of #131197 - EFanZh:avoid-emptyness-check-in-peekmut-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`.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/binary_heap/mod.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 5e59abf54ee..59f10b09c73 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -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() } } } |
