Skip to content

Commit 3e50038

Browse files
committed
Auto merge of #101999 - the8472:source-lines-partition-point, r=davidtwco
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.
2 parents 7a8636c + 40b3726 commit 3e50038

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

compiler/rustc_span/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1631,10 +1631,9 @@ impl SourceFile {
16311631
/// number. If the source_file is empty or the position is located before the
16321632
/// first line, `None` is returned.
16331633
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
1634-
self.lines(|lines| match lines.binary_search(&pos) {
1635-
Ok(idx) => Some(idx),
1636-
Err(0) => None,
1637-
Err(idx) => Some(idx - 1),
1634+
self.lines(|lines| match lines.partition_point(|x| x <= &pos) {
1635+
0 => None,
1636+
i => Some(i - 1),
16381637
})
16391638
}
16401639

0 commit comments

Comments
 (0)