File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ use alloc::collections::BTreeMap;
1111use core:: cell:: RefCell ;
1212#[ cfg( span_locations) ]
1313use core:: cmp;
14+ #[ cfg( all( span_locations, not( fuzzing) ) ) ]
15+ use core:: cmp:: Ordering ;
1416use core:: fmt:: { self , Debug , Display , Write } ;
1517use core:: mem:: ManuallyDrop ;
1618#[ cfg( span_locations) ]
@@ -456,12 +458,19 @@ impl SourceMap {
456458 }
457459
458460 fn find ( & self , span : Span ) -> usize {
459- for ( i, file) in self . files . iter ( ) . enumerate ( ) {
460- if file. span_within ( span) {
461- return i;
461+ match self . files . binary_search_by ( |file| {
462+ if file. span . hi < span. lo {
463+ Ordering :: Less
464+ } else if file. span . lo > span. hi {
465+ Ordering :: Greater
466+ } else {
467+ assert ! ( file. span_within( span) ) ;
468+ Ordering :: Equal
462469 }
470+ } ) {
471+ Ok ( i) => i,
472+ Err ( _) => unreachable ! ( "Invalid span with no related FileInfo!" ) ,
463473 }
464- unreachable ! ( "Invalid span with no related FileInfo!" ) ;
465474 }
466475
467476 fn filepath ( & self , span : Span ) -> String {
You can’t perform that action at this time.
0 commit comments