Skip to content

Commit

Permalink
Rollup merge of #69434 - petrochenkov:metabs, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
rustc_metadata: Use binary search from standard library

instead of a hand rolled one.

Noticed while reviewing #68941.
  • Loading branch information
Dylan-DPC authored Feb 26, 2020
2 parents d799f2d + 4dbdadf commit c076027
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,12 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
{
last_source_file
} else {
let mut a = 0;
let mut b = imported_source_files.len();

while b - a > 1 {
let m = (a + b) / 2;
if imported_source_files[m].original_start_pos > lo {
b = m;
} else {
a = m;
}
}
let index = imported_source_files
.binary_search_by_key(&lo, |source_file| source_file.original_start_pos)
.unwrap_or_else(|index| index - 1);

self.last_source_file_index = a;
&imported_source_files[a]
self.last_source_file_index = index;
&imported_source_files[index]
}
};

Expand Down

0 comments on commit c076027

Please sign in to comment.