use partition_point instead of binary_search when looking up source lines
In local benchmarks this results in 0.4% fewer cycles in a critical sequential section when compiling libcore.
This commit is contained in:
parent
98ad6a5519
commit
40b37268eb
1 changed files with 3 additions and 4 deletions
|
@ -1631,10 +1631,9 @@ impl SourceFile {
|
||||||
/// number. If the source_file is empty or the position is located before the
|
/// number. If the source_file is empty or the position is located before the
|
||||||
/// first line, `None` is returned.
|
/// first line, `None` is returned.
|
||||||
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
|
pub fn lookup_line(&self, pos: BytePos) -> Option<usize> {
|
||||||
self.lines(|lines| match lines.binary_search(&pos) {
|
self.lines(|lines| match lines.partition_point(|x| x <= &pos) {
|
||||||
Ok(idx) => Some(idx),
|
0 => None,
|
||||||
Err(0) => None,
|
i => Some(i - 1),
|
||||||
Err(idx) => Some(idx - 1),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue