about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGiacomo Stevanato <giaco.stevanato@gmail.com>2020-11-07 21:27:30 +0100
committerGiacomo Stevanato <giaco.stevanato@gmail.com>2020-11-07 22:20:26 +0100
commit25b3f61c3821fd597961f9dd394482b71600e859 (patch)
tree45cdc6d93dd03bef508834f8c863363052c86dff
parent6dfcf9afde98b4e873bfb0012e2efa0f058cc19d (diff)
downloadrust-25b3f61c3821fd597961f9dd394482b71600e859.tar.gz
rust-25b3f61c3821fd597961f9dd394482b71600e859.zip
Remove useless branches from sift_down_range loop
-rw-r--r--library/alloc/src/collections/binary_heap.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs
index 10ed99b2943..2d68146249b 100644
--- a/library/alloc/src/collections/binary_heap.rs
+++ b/library/alloc/src/collections/binary_heap.rs
@@ -531,19 +531,19 @@ 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;
+            while child < end - 1 {
                 // compare with the greater of the two children
-                if right < end && hole.get(child) <= hole.get(right) {
-                    child = right;
-                }
+                child += (hole.get(child) <= hole.get(child + 1)) as usize;
                 // if we are already in order, stop.
                 if hole.element() >= hole.get(child) {
-                    break;
+                    return;
                 }
                 hole.move_to(child);
                 child = 2 * hole.pos() + 1;
             }
+            if child == end - 1 && hole.element() < hole.get(child) {
+                hole.move_to(child);
+            }
         }
     }