Added SAFETY comment as request
This commit is contained in:
parent
8d1575365d
commit
387568cd56
@ -495,6 +495,10 @@ impl<T: Ord> BinaryHeap<T> {
|
||||
let mut end = self.len();
|
||||
while end > 1 {
|
||||
end -= 1;
|
||||
// SAFETY: `end` goes from `self.len() - 1` to 1 (both included),
|
||||
// so it's always a valid index to access.
|
||||
// It is safe to access index 0 (i.e. `ptr`), because
|
||||
// 1 <= end < self.len(), which means self.len() >= 2.
|
||||
unsafe {
|
||||
let ptr = self.data.as_mut_ptr();
|
||||
ptr::swap(ptr, ptr.add(end));
|
||||
|
Loading…
Reference in New Issue
Block a user