From 0fd3bbe6cf5100ff3bcddc4daffbaa02f9de04d5 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 1 Oct 2022 01:06:35 -0700 Subject: [PATCH] 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. --- compiler/rustc_span/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 366fd9d2cd1c3..d8ba3d57864d6 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 { - 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 {