Avoid emptiness check in PeekMut::pop
· qinheping/verify-rust-std@8cfa0ca (original) (raw)
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> { | ||
374 | 374 | // the caller could've mutated the element. It is removed from the |
375 | 375 | // heap on the next line and pop() is not sensitive to its value. |
376 | 376 | } |
377 | - this.heap.pop().unwrap() | |
377 | + | |
378 | +// SAFETY: Have a `PeekMut` element proves that the associated binary heap being non-empty, | |
379 | +// so the `pop` operation will not fail. | |
380 | +unsafe { this.heap.pop().unwrap_unchecked() } | |
378 | 381 | } |
379 | 382 | } |
380 | 383 |