Skip to content

Commit

Permalink
compress the function, remove the assert check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanqun Lu committed Oct 12, 2019
1 parent e039534 commit 63cb2fa
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/libsyntax/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,17 +878,8 @@ impl SourceMap {

// Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize {
let files = self.files.borrow();
let files = &files.source_files;
let count = files.len();

// (p - 1) below will not underflow, this follows previous implementation's assumption.
assert!(count >= 1);
let ret = files.binary_search_by_key(&pos, |key| key.start_pos).unwrap_or_else(|p| p - 1);

assert!(ret < count, "position {} does not resolve to a source location", pos.to_usize());

return ret;
self.files.borrow().source_files.binary_search_by_key(&pos, |key| key.start_pos)
.unwrap_or_else(|p| p - 1)
}

pub fn count_lines(&self) -> usize {
Expand Down

0 comments on commit 63cb2fa

Please sign in to comment.