Skip to content

Commit

Permalink
Auto merge of #101999 - the8472:source-lines-partition-point, r=david…
Browse files Browse the repository at this point in the history
…twco

use partition_point instead of binary_search when looking up source lines

In local benchmarks this results in 0.4% fewer cycles in a critical sequential section when compiling libcore.
  • Loading branch information
bors committed Sep 22, 2022
2 parents 7a8636c + 40b3726 commit 3e50038
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,9 @@ impl SourceFile {
/// number. If the source_file is empty or the position is located before the
/// first line, `None` is returned.
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
self.lines(|lines| match lines.binary_search(&pos) {
Ok(idx) => Some(idx),
Err(0) => None,
Err(idx) => Some(idx - 1),
self.lines(|lines| match lines.partition_point(|x| x <= &pos) {
0 => None,
i => Some(i - 1),
})
}

Expand Down

0 comments on commit 3e50038

Please sign in to comment.