Use partition_point in SourceMap::lookup_source_file_idx.

This makes it (a) a little simpler, and (b) more similar to
`SourceFile::lookup_line`.
This commit is contained in:
Nicholas Nethercote 2023-06-28 10:37:43 +10:00
parent b4c6e19ade
commit 45fcd1d0c5

View File

@ -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 {