about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorGiacomo Stevanato <giaco.stevanato@gmail.com>2020-11-07 20:01:47 +0100
committerGiacomo Stevanato <giaco.stevanato@gmail.com>2020-11-07 22:20:26 +0100
commit6dfcf9afde98b4e873bfb0012e2efa0f058cc19d (patch)
tree0a0b7bedf0353c2ec1057813585f5e01e5521822 /library/alloc/src
parentdc06a36074f04c6a77b5834f2950011d49607898 (diff)
downloadrust-6dfcf9afde98b4e873bfb0012e2efa0f058cc19d.tar.gz
rust-6dfcf9afde98b4e873bfb0012e2efa0f058cc19d.zip
Remove branches from sift_down_to_bottom loop
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/collections/binary_heap.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs
index b67c72d7136..10ed99b2943 100644
--- a/library/alloc/src/collections/binary_heap.rs
+++ b/library/alloc/src/collections/binary_heap.rs
@@ -563,15 +563,14 @@ impl<T: Ord> BinaryHeap<T> {
         unsafe {
             let mut hole = Hole::new(&mut self.data, pos);
             let mut child = 2 * pos + 1;
-            while child < end {
-                let right = child + 1;
-                // compare with the greater of the two children
-                if right < end && hole.get(child) <= hole.get(right) {
-                    child = right;
-                }
+            while child < end - 1 {
+                child += (hole.get(child) <= hole.get(child + 1)) as usize;
                 hole.move_to(child);
                 child = 2 * hole.pos() + 1;
             }
+            if child == end - 1 {
+                hole.move_to(child);
+            }
             pos = hole.pos;
         }
         self.sift_up(start, pos);