File tree Expand file tree Collapse file tree 2 files changed +16
-20
lines changed Expand file tree Collapse file tree 2 files changed +16
-20
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: d3eb3b42aa59c44c25c7f51cfa07a06d05b6a073
2
+ refs/heads/master: 2361b655261ad48d0eefdaf706ecac6af819e9ad
Original file line number Diff line number Diff line change @@ -28,26 +28,22 @@ fn next_line(filemap file, uint pos) {
28
28
}
29
29
30
30
fn lookup_pos ( codemap map, uint pos) -> loc {
31
- auto i = _vec. len [ filemap] ( map. files ) ;
32
- while ( i > 0 u) {
33
- i -= 1 u;
34
- auto f = map. files . ( i) ;
35
- if ( f. start_pos <= pos) {
36
- // FIXME this can be a binary search if we need to be faster
37
- auto line = _vec. len [ uint] ( f. lines ) ;
38
- while ( line > 0 u) {
39
- line -= 1 u;
40
- auto line_start = f. lines . ( line) ;
41
- if ( line_start <= pos) {
42
- ret rec ( filename=f. name ,
43
- line=line + 1 u,
44
- col=pos-line_start) ;
45
- }
46
- }
47
- }
31
+ auto a = 0 u; auto b = _vec. len [ filemap] ( map. files ) ;
32
+ while ( b - a > 1 u) {
33
+ auto m = ( a + b) / 2 u;
34
+ if ( map. files . ( m) . start_pos > pos) { b = m; }
35
+ else { a = m; }
48
36
}
49
- log_err #fmt( "Failed to find a location for character %u" , pos) ;
50
- fail;
37
+ auto f = map. files . ( a) ;
38
+ a = 0 u; b = _vec. len [ uint] ( f. lines ) ;
39
+ while ( b - a > 1 u) {
40
+ auto m = ( a + b) / 2 u;
41
+ if ( f. lines . ( m) > pos) { b = m; }
42
+ else { a = m; }
43
+ }
44
+ ret rec( filename=f. name ,
45
+ line=a + 1 u,
46
+ col=pos - f. lines . ( a) ) ;
51
47
}
52
48
53
49
//
You can’t perform that action at this time.
0 commit comments