diff options
| author | bors <bors@rust-lang.org> | 2019-10-13 11:36:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-13 11:36:52 +0000 |
| commit | aa2ae564d391a3da10bca2a79ab529a9925fbe58 (patch) | |
| tree | c2cd4ba7039146bc964171693b6978296f585a72 /src/libsyntax/source_map.rs | |
| parent | 29b6e0f0a1d1a37f8dc729484a64e59bf0b9a0a3 (diff) | |
| parent | b82859171cda6380546ad4802015dd803e4847a0 (diff) | |
| download | rust-aa2ae564d391a3da10bca2a79ab529a9925fbe58.tar.gz rust-aa2ae564d391a3da10bca2a79ab529a9925fbe58.zip | |
Auto merge of #65368 - Centril:rollup-lb7fe48, r=Centril
Rollup of 13 pull requests Successful merges: - #65039 (Document missing deny by default lints) - #65069 (Implement Clone::clone_from for VecDeque) - #65165 (Improve docs on some char boolean methods) - #65248 (Suggest `if let` on `let` refutable binding) - #65250 (resolve: fix error title regarding private constructors) - #65295 (Move diagnostics code out of the critical path) - #65320 (Report `CONST_ERR` lint in external macros) - #65327 (replace the hand-written binary search with the library one) - #65339 (do not reference LLVM for our concurrency memory model) - #65357 (syntax: simplify maybe_annotate_with_ascription) - #65358 (simplify maybe_stage_features) - #65359 (simplify integer_lit) - #65360 (mbe: reduce panictry! uses.) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax/source_map.rs')
| -rw-r--r-- | src/libsyntax/source_map.rs | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/src/libsyntax/source_map.rs b/src/libsyntax/source_map.rs index 7d0d2392945..5e569f9dae3 100644 --- a/src/libsyntax/source_map.rs +++ b/src/libsyntax/source_map.rs @@ -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 { |
