Skip to content

Commit 4dbdadf

Browse files
committed
rustc_metadata: Use binary search from standard library
instead of a hand rolled one.
1 parent d9a328a commit 4dbdadf

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/librustc_metadata/rmeta/decoder.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -408,20 +408,12 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
408408
{
409409
last_source_file
410410
} else {
411-
let mut a = 0;
412-
let mut b = imported_source_files.len();
413-
414-
while b - a > 1 {
415-
let m = (a + b) / 2;
416-
if imported_source_files[m].original_start_pos > lo {
417-
b = m;
418-
} else {
419-
a = m;
420-
}
421-
}
411+
let index = imported_source_files
412+
.binary_search_by_key(&lo, |source_file| source_file.original_start_pos)
413+
.unwrap_or_else(|index| index - 1);
422414

423-
self.last_source_file_index = a;
424-
&imported_source_files[a]
415+
self.last_source_file_index = index;
416+
&imported_source_files[index]
425417
}
426418
};
427419

0 commit comments

Comments
 (0)