Skip to content

Commit a326e0c

Browse files
committed
---
yaml --- r: 2195 b: refs/heads/master c: 2361b65 h: refs/heads/master i: 2193: 3508d75 2191: db015c0 v: v3
1 parent 4ac9fac commit a326e0c

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d3eb3b42aa59c44c25c7f51cfa07a06d05b6a073
2+
refs/heads/master: 2361b655261ad48d0eefdaf706ecac6af819e9ad

trunk/src/comp/front/codemap.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,22 @@ fn next_line(filemap file, uint pos) {
2828
}
2929

3030
fn lookup_pos(codemap map, uint pos) -> loc {
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) {
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 > 0u) {
39-
line -= 1u;
40-
auto line_start = f.lines.(line);
41-
if (line_start <= pos) {
42-
ret rec(filename=f.name,
43-
line=line + 1u,
44-
col=pos-line_start);
45-
}
46-
}
47-
}
31+
auto a = 0u; auto b = _vec.len[filemap](map.files);
32+
while (b - a > 1u) {
33+
auto m = (a + b) / 2u;
34+
if (map.files.(m).start_pos > pos) { b = m; }
35+
else { a = m; }
4836
}
49-
log_err #fmt("Failed to find a location for character %u", pos);
50-
fail;
37+
auto f = map.files.(a);
38+
a = 0u; b = _vec.len[uint](f.lines);
39+
while (b - a > 1u) {
40+
auto m = (a + b) / 2u;
41+
if (f.lines.(m) > pos) { b = m; }
42+
else { a = m; }
43+
}
44+
ret rec(filename=f.name,
45+
line=a + 1u,
46+
col=pos - f.lines.(a));
5147
}
5248

5349
//

0 commit comments

Comments
 (0)