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;
11
11
use core:: cell:: RefCell ;
12
12
#[ cfg( span_locations) ]
13
13
use core:: cmp;
14
+ #[ cfg( all( span_locations, not( fuzzing) ) ) ]
15
+ use core:: cmp:: Ordering ;
14
16
use core:: fmt:: { self , Debug , Display , Write } ;
15
17
use core:: mem:: ManuallyDrop ;
16
18
#[ cfg( span_locations) ]
@@ -456,12 +458,19 @@ impl SourceMap {
456
458
}
457
459
458
460
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
462
469
}
470
+ } ) {
471
+ Ok ( i) => return i,
472
+ Err ( _) => unreachable ! ( "Invalid span with no related FileInfo!" ) ,
463
473
}
464
- unreachable ! ( "Invalid span with no related FileInfo!" ) ;
465
474
}
466
475
467
476
fn filepath ( & self , span : Span ) -> String {
You can’t perform that action at this time.
0 commit comments