Skip to content

Commit

Permalink
Use partition_point in SourceMap::lookup_source_file_idx.
Browse files Browse the repository at this point in the history
This makes it (a) a little simpler, and (b) more similar to
`SourceFile::lookup_line`.
  • Loading branch information
nnethercote committed Jun 29, 2023
1 parent b4c6e19 commit 45fcd1d
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,11 +1072,7 @@ impl SourceMap {
/// This index is guaranteed to be valid for the lifetime of this `SourceMap`,
/// since `source_files` is a `MonotonicVec`
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize {
self.files
.borrow()
.source_files
.binary_search_by_key(&pos, |key| key.start_pos)
.unwrap_or_else(|p| p - 1)
self.files.borrow().source_files.partition_point(|x| x.start_pos <= pos) - 1
}

pub fn count_lines(&self) -> usize {
Expand Down

0 comments on commit 45fcd1d

Please sign in to comment.