File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Expand file tree Collapse file tree 1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -18,35 +18,32 @@ fn new_codemap() -> codemap {
18
18
}
19
19
20
20
fn new_filemap ( str filename , uint start_pos ) -> filemap {
21
- let vec[ uint] lines = vec ( ) ;
22
21
ret @rec( name=filename,
23
22
start_pos=start_pos,
24
- mutable lines=lines ) ;
23
+ mutable lines=vec ( 0 u ) ) ;
25
24
}
26
25
27
26
fn next_line ( filemap file, uint pos) {
28
27
_vec. push [ uint] ( file. lines , pos) ;
29
28
}
30
29
31
30
fn lookup_pos ( codemap map, uint pos) -> loc {
32
- for ( filemap f in map. files) {
33
- if ( f. start_pos < pos) {
34
- auto line_num = 1 u;
35
- auto line_start = 0 u;
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
36
// FIXME this can be a binary search if we need to be faster
37
- for ( uint line_start_ in f. lines) {
38
- // FIXME duplicate code due to lack of working break
39
- if ( line_start_ > pos) {
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) {
40
42
ret rec ( filename=f. name ,
41
- line=line_num ,
43
+ line=line + 1 u ,
42
44
col=pos-line_start) ;
43
45
}
44
- line_start = line_start_;
45
- line_num += 1 u;
46
46
}
47
- ret rec( filename=f. name ,
48
- line=line_num,
49
- col=pos-line_start) ;
50
47
}
51
48
}
52
49
log #fmt( "Failed to find a location for character %u" , pos) ;
You can’t perform that action at this time.
0 commit comments