Skip to content

[rustc_data_structures] Use partition_point to find slice range end. #114231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions compiler/rustc_data_structures/src/binary_search_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,10 @@ where
return &[];
};

// Now search forward to find the *last* one.
let mut end = start;
let mut previous = start;
let mut step = 1;
loop {
end = end.saturating_add(step).min(size);
if end == size || key_fn(&data[end]) != *key {
break;
}
previous = end;
step *= 2;
}
step = end - previous;
while step > 1 {
let half = step / 2;
let mid = end - half;
if key_fn(&data[mid]) != *key {
end = mid;
}
step -= half;
}
// Find the first entry with key > `key`. Skip `start` entries since
// key_fn(&data[start]) == *key
let offset = start + 1;
let end = data[offset..].partition_point(|x| key_fn(x) <= *key) + offset;

&data[start..end]
}