File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change @@ -882,21 +882,13 @@ impl SourceMap {
882882 let files = & files. source_files ;
883883 let count = files. len ( ) ;
884884
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- }
885+ // (p - 1) below will not underflow, this follows previous implementation's assumption.
886+ assert ! ( count >= 1 ) ;
887+ let ret = files. binary_search_by_key ( & pos, |key| key. start_pos ) . unwrap_or_else ( |p| p - 1 ) ;
896888
897- assert ! ( a < count, "position {} does not resolve to a source location" , pos. to_usize( ) ) ;
889+ assert ! ( ret < count, "position {} does not resolve to a source location" , pos. to_usize( ) ) ;
898890
899- return a ;
891+ return ret ;
900892 }
901893
902894 pub fn count_lines ( & self ) -> usize {
You can’t perform that action at this time.
0 commit comments