Rollup merge of #65327 - guanqun:remove-hand-binary-search, r=petrochenkov
replace the hand-written binary search with the library one
This commit is contained in:
commit
af8a6e5e6d
1 changed files with 2 additions and 19 deletions
|
|
@ -878,25 +878,8 @@ impl SourceMap {
|
|||
|
||||
// Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
|
||||
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize {
|
||||
let files = self.files.borrow();
|
||||
let files = &files.source_files;
|
||||
let count = files.len();
|
||||
|
||||
// Binary search for the `SourceFile`.
|
||||
let mut a = 0;
|
||||
let mut b = count;
|
||||
while b - a > 1 {
|
||||
let m = (a + b) / 2;
|
||||
if files[m].start_pos > pos {
|
||||
b = m;
|
||||
} else {
|
||||
a = m;
|
||||
}
|
||||
}
|
||||
|
||||
assert!(a < count, "position {} does not resolve to a source location", pos.to_usize());
|
||||
|
||||
return a;
|
||||
self.files.borrow().source_files.binary_search_by_key(&pos, |key| key.start_pos)
|
||||
.unwrap_or_else(|p| p - 1)
|
||||
}
|
||||
|
||||
pub fn count_lines(&self) -> usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue