Skip to content

Commit 8cfa0ca

Browse files
committed
Avoid emptiness check in PeekMut::pop
1 parent d5599a7 commit 8cfa0ca

File tree

1 file changed

+4
-1
lines changed
  • alloc/src/collections/binary_heap

1 file changed

+4
-1
lines changed

alloc/src/collections/binary_heap/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> {
374374
// the caller could've mutated the element. It is removed from the
375375
// heap on the next line and pop() is not sensitive to its value.
376376
}
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() }
378381
}
379382
}
380383

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy