mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-29 03:37:26 +03:00
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:
@@ -1072,11 +1072,7 @@ pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos {
|
||||
/// 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 {
|
||||
|
||||
Reference in New Issue
Block a user