about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorTaras Tsugrii <taras.tsugriy@gmail.com>2023-08-08 11:03:19 -0700
committerTaras Tsugrii <taras.tsugriy@gmail.com>2023-08-09 11:35:31 -0700
commit1e347e1e730a30b3cdacccc094e62dbe6d74f9fa (patch)
tree1c4c93bb6bd50318c0557e1739973a146e783c08 /src
parent31e9f7a6ef3ec981d4c9797f90f303e63c31f0b4 (diff)
downloadrust-1e347e1e730a30b3cdacccc094e62dbe6d74f9fa.tar.gz
rust-1e347e1e730a30b3cdacccc094e62dbe6d74f9fa.zip
Use Vec's binary search instead of hand-written one.
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/src/concurrency/range_object_map.rs22
1 files changed, 5 insertions, 17 deletions
diff --git a/src/tools/miri/src/concurrency/range_object_map.rs b/src/tools/miri/src/concurrency/range_object_map.rs
index 89c009933bb..98878991f53 100644
--- a/src/tools/miri/src/concurrency/range_object_map.rs
+++ b/src/tools/miri/src/concurrency/range_object_map.rs
@@ -42,30 +42,18 @@ impl<T> RangeObjectMap<T> {
     /// in an existing allocation, then returns Err containing the position
     /// where such allocation should be inserted
     fn find_offset(&self, offset: Size) -> Result<Position, Position> {
-        // We do a binary search.
-        let mut left = 0usize; // inclusive
-        let mut right = self.v.len(); // exclusive
-        loop {
-            if left == right {
-                // No element contains the given offset. But the
-                // position is where such element should be placed at.
-                return Err(left);
-            }
-            let candidate = left.checked_add(right).unwrap() / 2;
-            let elem = &self.v[candidate];
+        self.v.binary_search_by(|elem| -> std::cmp::Ordering {
             if offset < elem.range.start {
                 // We are too far right (offset is further left).
-                debug_assert!(candidate < right); // we are making progress
-                right = candidate;
+                std::cmp::Ordering::Greater
             } else if offset >= elem.range.end() {
                 // We are too far left (offset is further right).
-                debug_assert!(candidate >= left); // we are making progress
-                left = candidate + 1;
+                std::cmp::Ordering::Less
             } else {
                 // This is it!
-                return Ok(candidate);
+                std::cmp::Ordering::Equal
             }
-        }
+        })
     }
 
     /// Determines whether a given access on `range` overlaps with