diff options
author | Martin Odersky <odersky@gmail.com> | 2015-02-07 18:07:14 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-02-07 18:07:20 +0100 |
commit | b2e8905678781db3a7903ab4b247b551e319408d (patch) | |
tree | 8c6c1ecb2ff52e6a0dbb94a35d14ec4a11da5554 /src/dotty/tools/dotc/util/SourceFile.scala | |
parent | 9641b2a417f203b5c2e88e6330b2230713471307 (diff) | |
download | dotty-b2e8905678781db3a7903ab4b247b551e319408d.tar.gz dotty-b2e8905678781db3a7903ab4b247b551e319408d.tar.bz2 dotty-b2e8905678781db3a7903ab4b247b551e319408d.zip |
Make line search logic in SourcePositions generally available.
Create an object Util for utility methods that are used in several places.
Diffstat (limited to 'src/dotty/tools/dotc/util/SourceFile.scala')
-rw-r--r-- | src/dotty/tools/dotc/util/SourceFile.scala | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index 4e1eb224a..c5d88d7bf 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -99,12 +99,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) { * Lines are numbered from 0 */ def offsetToLine(offset: Int): Int = { - val lines = lineIndices - def findLine(lo: Int, hi: Int, mid: Int): Int = - if (offset < lines(mid)) findLine(lo, mid - 1, (lo + mid - 1) / 2) - else if (offset >= lines(mid + 1)) findLine(mid + 1, hi, (mid + 1 + hi) / 2) - else mid - lastLine = findLine(0, lines.length, lastLine) + lastLine = Util.bestFit(lineIndices, offset, lastLine) lastLine } |