Skip to content

Commit 40b3726

Browse files
committed
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.
1 parent 98ad6a5 commit 40b3726

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)