File tree 1 file changed +5
-17
lines changed
src/tools/miri/src/concurrency
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> {
42
42
/// in an existing allocation, then returns Err containing the position
43
43
/// where such allocation should be inserted
44
44
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 {
56
46
if offset < elem. range . start {
57
47
// 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
60
49
} else if offset >= elem. range . end ( ) {
61
50
// 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
64
52
} else {
65
53
// This is it!
66
- return Ok ( candidate ) ;
54
+ std :: cmp :: Ordering :: Equal
67
55
}
68
- }
56
+ } )
69
57
}
70
58
71
59
/// Determines whether a given access on `range` overlaps with
You can’t perform that action at this time.
0 commit comments