about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-02-26 15:34:33 +0100
committerGitHub <noreply@github.com>2020-02-26 15:34:33 +0100
commitc0760279b3c0b2ae56dce8e569eeec585bb29c92 (patch)
treecdaca3a47a21670e62dc473fd00e6b843411c011
parentd799f2deb10e98cab17439ad4f38204cc3dc406c (diff)
parent4dbdadf94dbfa7eaf89e54d849ae6287de6b89c5 (diff)
downloadrust-c0760279b3c0b2ae56dce8e569eeec585bb29c92.tar.gz
rust-c0760279b3c0b2ae56dce8e569eeec585bb29c92.zip
Rollup merge of #69434 - petrochenkov:metabs, r=Mark-Simulacrum
rustc_metadata: Use binary search from standard library

instead of a hand rolled one.

Noticed while reviewing https://github.com/rust-lang/rust/pull/68941.
-rw-r--r--src/librustc_metadata/rmeta/decoder.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs
index 01fd637b20e..3dacd2cbe95 100644
--- a/src/librustc_metadata/rmeta/decoder.rs
+++ b/src/librustc_metadata/rmeta/decoder.rs
@@ -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]
             }
         };