Skip to content

Commit c0d0b71

Browse files
committed
Fix codemap.lookup_pos
Previously, it would place every single location in the first file of the crate that was parsed.
1 parent 129c839 commit c0d0b71

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/comp/front/codemap.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,32 @@ fn new_codemap() -> codemap {
1818
}
1919

2020
fn new_filemap(str filename, uint start_pos) -> filemap {
21-
let vec[uint] lines = vec();
2221
ret @rec(name=filename,
2322
start_pos=start_pos,
24-
mutable lines=lines);
23+
mutable lines=vec(0u));
2524
}
2625

2726
fn next_line(filemap file, uint pos) {
2827
_vec.push[uint](file.lines, pos);
2928
}
3029

3130
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 = 1u;
35-
auto line_start = 0u;
31+
auto i = _vec.len[filemap](map.files);
32+
while (i > 0u) {
33+
i -= 1u;
34+
auto f = map.files.(i);
35+
if (f.start_pos <= pos) {
3636
// 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 > 0u) {
39+
line -= 1u;
40+
auto line_start = f.lines.(line);
41+
if (line_start <= pos) {
4042
ret rec(filename=f.name,
41-
line=line_num,
43+
line=line + 1u,
4244
col=pos-line_start);
4345
}
44-
line_start = line_start_;
45-
line_num += 1u;
4646
}
47-
ret rec(filename=f.name,
48-
line=line_num,
49-
col=pos-line_start);
5047
}
5148
}
5249
log #fmt("Failed to find a location for character %u", pos);

0 commit comments

Comments
 (0)