Skip to content

Commit

Permalink
Auto merge of rust-lang#102536 - scottmcm:lookup_line-tweak, r=jackh726
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Oct 24, 2022
2 parents 56f1325 + 0fd3bbe commit 4b5fcae
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,7 @@ 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.partition_point(|x| x <= &pos) {
0 => None,
i => Some(i - 1),
})
self.lines(|lines| lines.partition_point(|x| x <= &pos).checked_sub(1))
}

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

0 comments on commit 4b5fcae

Please sign in to comment.