File tree Expand file tree Collapse file tree 1 file changed +2
-19
lines changed Expand file tree Collapse file tree 1 file changed +2
-19
lines changed Original file line number Diff line number Diff line change @@ -878,25 +878,8 @@ impl SourceMap {
878878
879879 // Returns the index of the `SourceFile` (in `self.files`) that contains `pos`.
880880 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 )
900883 }
901884
902885 pub fn count_lines ( & self ) -> usize {
You can’t perform that action at this time.
0 commit comments