Skip to content

Commit 0fd3bbe

Browse files
committed
Shorten the lookup_line code slightly
The `match` looks like it's exactly the same as `checked_sub(1)`, so we might as well see if perf says we can just do that to save a couple lines.
1 parent fe217c2 commit 0fd3bbe

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

compiler/rustc_span/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1628,10 +1628,7 @@ impl SourceFile {
16281628
/// number. If the source_file is empty or the position is located before the
16291629
/// first line, `None` is returned.
16301630
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
1631-
self.lines(|lines| match lines.partition_point(|x| x <= &pos) {
1632-
0 => None,
1633-
i => Some(i - 1),
1634-
})
1631+
self.lines(|lines| lines.partition_point(|x| x <= &pos).checked_sub(1))
16351632
}
16361633

16371634
pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> {

0 commit comments

Comments
 (0)