From b2e8905678781db3a7903ab4b247b551e319408d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 7 Feb 2015 18:07:14 +0100 Subject: Make line search logic in SourcePositions generally available. Create an object Util for utility methods that are used in several places. --- src/dotty/tools/dotc/util/SourceFile.scala | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/dotty/tools/dotc/util/SourceFile.scala') 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 } -- cgit v1.2.3