mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-31 17:12:53 +00: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:
parent
b4c6e19ade
commit
45fcd1d0c5
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user