Skip to content

Commit

Permalink
Rollup merge of rust-lang#65327 - guanqun:remove-hand-binary-search, …
Browse files Browse the repository at this point in the history
…r=petrochenkov

replace the hand-written binary search with the library one
  • Loading branch information
Centril authored Oct 13, 2019
2 parents 643261a + 63cb2fa commit af8a6e5
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/libsyntax/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af8a6e5

Please sign in to comment.