Chromium Code Reviews| Index: lib/compiler/implementation/source_file.dart |
| diff --git a/lib/compiler/implementation/source_file.dart b/lib/compiler/implementation/source_file.dart |
| index 2255620b3ec2e036cff9a707b54456a67d54bfc8..c891e223e3ff5acdaa3253a9b051719c3153ffaa 100644 |
| --- a/lib/compiler/implementation/source_file.dart |
| +++ b/lib/compiler/implementation/source_file.dart |
| @@ -39,13 +39,25 @@ class SourceFile { |
| } |
| int getLine(int position) { |
| - // TODO(jimhug): Implement as binary search. |
| - var starts = lineStarts; |
| - for (int i=0; i < starts.length; i++) { |
| - if (starts[i] > position) return i-1; |
| + if (position < 0 || text.length <= position) { |
| + throw 'bad position #$position in file $filename with ' |
| + 'length ${text.length}.'; |
| } |
| - throw 'bad position #$position in file $filename with ' |
| - 'length ${text.length}.'; |
| + List<int> starts = lineStarts; |
| + int first = 0; |
| + int count = starts.length; |
| + while (count > 1) { |
| + int step = count >> 1; |
|
floitsch
2012/09/10 09:08:20
count ~/ 2
podivilov
2012/09/10 09:45:45
Done.
|
| + int middle = first + step; |
| + int lineStart = starts[middle]; |
| + if (position < lineStart) { |
| + count = step; |
| + } else { |
| + first = middle; |
| + count -= step; |
| + } |
| + } |
| + return first; |
| } |
| int getColumn(int line, int position) { |