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:
parent
fe217c28ff
commit
0fd3bbe6cf
@ -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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user