1
Fork 0

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.
This commit is contained in:
bors 2022-10-24 07:24:45 +00:00
commit 4b5fcae32d

View file

@ -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> {