Skip to content

Commit 6e6e244

Browse files
committed
Use provided methods of Compare trait
1 parent 848c784 commit 6e6e244

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/binary_heap.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,8 +1081,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
10811081
// it's a valid index and also != hole.pos().
10821082
if self
10831083
.cmp
1084-
.compare(hole.element(), unsafe { hole.get(parent) })
1085-
!= Ordering::Greater
1084+
.compares_le(hole.element(), unsafe { hole.get(parent) })
10861085
{
10871086
break;
10881087
}
@@ -1114,14 +1113,15 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
11141113
// child + 1 == 2 * hole.pos() + 2 != hole.pos().
11151114
// FIXME: 2 * hole.pos() + 1 or 2 * hole.pos() + 2 could overflow
11161115
// if T is a ZST
1117-
child += unsafe {
1118-
self.cmp.compare(hole.get(child), hole.get(child + 1)) != Ordering::Greater
1119-
} as usize;
1116+
child += unsafe { self.cmp.compares_le(hole.get(child), hole.get(child + 1)) } as usize;
11201117

11211118
// if we are already in order, stop.
11221119
// SAFETY: child is now either the old child or the old child+1
11231120
// We already proven that both are < self.len() and != hole.pos()
1124-
if self.cmp.compare(hole.element(), unsafe { hole.get(child) }) != Ordering::Less {
1121+
if self
1122+
.cmp
1123+
.compares_ge(hole.element(), unsafe { hole.get(child) })
1124+
{
11251125
return;
11261126
}
11271127

@@ -1133,7 +1133,9 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
11331133
// SAFETY: && short circuit, which means that in the
11341134
// second condition it's already true that child == end - 1 < self.len().
11351135
if child == end - 1
1136-
&& self.cmp.compare(hole.element(), unsafe { hole.get(child) }) == Ordering::Less
1136+
&& self
1137+
.cmp
1138+
.compares_lt(hole.element(), unsafe { hole.get(child) })
11371139
{
11381140
// SAFETY: child is already proven to be a valid index and
11391141
// child == 2 * hole.pos() + 1 != hole.pos().
@@ -1176,9 +1178,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
11761178
// child + 1 == 2 * hole.pos() + 2 != hole.pos().
11771179
// FIXME: 2 * hole.pos() + 1 or 2 * hole.pos() + 2 could overflow
11781180
// if T is a ZST
1179-
child += unsafe {
1180-
self.cmp.compare(hole.get(child), hole.get(child + 1)) != Ordering::Greater
1181-
} as usize;
1181+
child += unsafe { self.cmp.compares_le(hole.get(child), hole.get(child + 1)) } as usize;
11821182

11831183
// SAFETY: Same as above
11841184
unsafe { hole.move_to(child) };

0 commit comments

Comments
 (0)