about summary refs log tree commit diff
path: root/compiler/rustc_span
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2022-10-01 01:06:35 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2022-10-01 01:06:35 -0700
commit0fd3bbe6cf5100ff3bcddc4daffbaa02f9de04d5 (patch)
tree9d4e64fa603531c8f0fc29078e2e2ccb5986a91e /compiler/rustc_span
parentfe217c28ffc6955f0927d8e8715d43d727debe5a (diff)
downloadrust-0fd3bbe6cf5100ff3bcddc4daffbaa02f9de04d5.tar.gz
rust-0fd3bbe6cf5100ff3bcddc4daffbaa02f9de04d5.zip
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.
Diffstat (limited to 'compiler/rustc_span')
-rw-r--r--compiler/rustc_span/src/lib.rs5
1 files changed, 1 insertions, 4 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 366fd9d2cd1..d8ba3d57864 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -1628,10 +1628,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> {