Skip to content

Commit 4b5fcae

Browse files
committed
Auto merge of rust-lang#102536 - scottmcm:lookup_line-tweak, r=jackh726
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.
2 parents 56f1325 + 0fd3bbe commit 4b5fcae

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
@@ -1631,10 +1631,7 @@ 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.partition_point(|x| x <= &pos) {
1635-
0 => None,
1636-
i => Some(i - 1),
1637-
})
1634+
self.lines(|lines| lines.partition_point(|x| x <= &pos).checked_sub(1))
16381635
}
16391636

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

0 commit comments

Comments
 (0)