diff options
| author | bors <bors@rust-lang.org> | 2022-10-24 07:24:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-24 07:24:45 +0000 |
| commit | 4b5fcae32d5e0db0f416fbfafbab63366486f0c3 (patch) | |
| tree | 1e2087a9d330af9014d992ae0a14edc21cd96901 | |
| parent | 56f132565eb31eeb9ec7e1800a6ab2ca354e710e (diff) | |
| parent | 0fd3bbe6cf5100ff3bcddc4daffbaa02f9de04d5 (diff) | |
Auto merge of #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.
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 91eef647713..842aa98bc9e 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -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> { |
