-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
replace the hand-written binary search with the library one #65327
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Looks like the previous version assumed that unsuccessful lookups cannot happen, but turns out they do happen (I've just checked) and the function returns a garbage index in this case. |
Ah, sorry, I misunderstood how this works, we are searching through intervals rather than precise values, of course the search will almost always return |
Could you compress the function a bit, like pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize {
self.files.borrow().source_files.binary_search_by_key(&pos, |key| key.start_pos)
.unwrap_or_else(|p| p - 1)
} The asserts don't make much sense here, we'll get a panic one way or another anyway if the number of files is zero. |
Thank you @petrochenkov for the review and the double check. I just pushed a new commit to compress the function as you suggested. Please help review again, thanks! |
@bors r+ rollup |
📌 Commit 63cb2fa has been approved by |
…r=petrochenkov replace the hand-written binary search with the library one
Rollup of 13 pull requests Successful merges: - #65039 (Document missing deny by default lints) - #65069 (Implement Clone::clone_from for VecDeque) - #65165 (Improve docs on some char boolean methods) - #65248 (Suggest `if let` on `let` refutable binding) - #65250 (resolve: fix error title regarding private constructors) - #65295 (Move diagnostics code out of the critical path) - #65320 (Report `CONST_ERR` lint in external macros) - #65327 (replace the hand-written binary search with the library one) - #65339 (do not reference LLVM for our concurrency memory model) - #65357 (syntax: simplify maybe_annotate_with_ascription) - #65358 (simplify maybe_stage_features) - #65359 (simplify integer_lit) - #65360 (mbe: reduce panictry! uses.) Failed merges: r? @ghost
No description provided.