mirror of
https://github.com/openharmony/third_party_rust_rust.git
synced 2026-07-19 19:53:38 -04:00
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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user