diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-10-13 13:34:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-13 13:34:37 +0200 |
| commit | af8a6e5e6d2b87f388f2b3145fbbede997152156 (patch) | |
| tree | 9739e51d2df8ee0fde518fc1ffcaeec14b83306a /src | |
| parent | 643261aad437d5f0b2e8af0702337df2f41b3318 (diff) | |
| parent | 63cb2fa1973e1fcff335f858f77496ba2c8d252c (diff) | |
| download | rust-af8a6e5e6d2b87f388f2b3145fbbede997152156.tar.gz rust-af8a6e5e6d2b87f388f2b3145fbbede997152156.zip | |
Rollup merge of #65327 - guanqun:remove-hand-binary-search, r=petrochenkov
replace the hand-written binary search with the library one
Diffstat (limited to 'src')
| -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 { |
