File tree Expand file tree Collapse file tree 1 file changed +5
-17
lines changed
src/tools/miri/src/concurrency Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Original file line number Diff line number Diff line change @@ -42,30 +42,18 @@ impl<T> RangeObjectMap<T> {
4242 /// in an existing allocation, then returns Err containing the position
4343 /// where such allocation should be inserted
4444 fn find_offset ( & self , offset : Size ) -> Result < Position , Position > {
45- // We do a binary search.
46- let mut left = 0usize ; // inclusive
47- let mut right = self . v . len ( ) ; // exclusive
48- loop {
49- if left == right {
50- // No element contains the given offset. But the
51- // position is where such element should be placed at.
52- return Err ( left) ;
53- }
54- let candidate = left. checked_add ( right) . unwrap ( ) / 2 ;
55- let elem = & self . v [ candidate] ;
45+ self . v . binary_search_by ( |elem| -> std:: cmp:: Ordering {
5646 if offset < elem. range . start {
5747 // We are too far right (offset is further left).
58- debug_assert ! ( candidate < right) ; // we are making progress
59- right = candidate;
48+ std:: cmp:: Ordering :: Greater
6049 } else if offset >= elem. range . end ( ) {
6150 // We are too far left (offset is further right).
62- debug_assert ! ( candidate >= left) ; // we are making progress
63- left = candidate + 1 ;
51+ std:: cmp:: Ordering :: Less
6452 } else {
6553 // This is it!
66- return Ok ( candidate ) ;
54+ std :: cmp :: Ordering :: Equal
6755 }
68- }
56+ } )
6957 }
7058
7159 /// Determines whether a given access on `range` overlaps with
You can’t perform that action at this time.
0 commit comments