File tree 1 file changed +2
-19
lines changed 1 file changed +2
-19
lines changed Original file line number Diff line number Diff line change @@ -878,25 +878,8 @@ impl SourceMap {
878
878
879
879
// Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
880
880
pub fn lookup_source_file_idx ( & self , pos : BytePos ) -> usize {
881
- let files = self . files . borrow ( ) ;
882
- let files = & files. source_files ;
883
- let count = files. len ( ) ;
884
-
885
- // Binary search for the `SourceFile`.
886
- let mut a = 0 ;
887
- let mut b = count;
888
- while b - a > 1 {
889
- let m = ( a + b) / 2 ;
890
- if files[ m] . start_pos > pos {
891
- b = m;
892
- } else {
893
- a = m;
894
- }
895
- }
896
-
897
- assert ! ( a < count, "position {} does not resolve to a source location" , pos. to_usize( ) ) ;
898
-
899
- return a;
881
+ self . files . borrow ( ) . source_files . binary_search_by_key ( & pos, |key| key. start_pos )
882
+ . unwrap_or_else ( |p| p - 1 )
900
883
}
901
884
902
885
pub fn count_lines ( & self ) -> usize {
You can’t perform that action at this time.
0 commit comments