diff options
author | Donna Malayeri <lindydonna@gmail.com> | 2011-03-07 22:35:36 +0000 |
---|---|---|
committer | Donna Malayeri <lindydonna@gmail.com> | 2011-03-07 22:35:36 +0000 |
commit | 3b467cdfe181953f60a8109410be205d8d9934c1 (patch) | |
tree | e90033b23328aab6554a6c66ff8021dbe2239d8c /src | |
parent | 3689a29fca753e51d72c6c81abf78dfc6ba51b92 (diff) | |
download | scala-3b467cdfe181953f60a8109410be205d8d9934c1.tar.gz scala-3b467cdfe181953f60a8109410be205d8d9934c1.tar.bz2 scala-3b467cdfe181953f60a8109410be205d8d9934c1.zip |
Modify BufferedSource to use a BufferedLineIter...
Modify BufferedSource to use a BufferedLineIterator to speed up
line-by-line reads on large files. Updated testfile which used this
class. Closes #4186. Review (of fft.check) by prokopec.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/io/BufferedSource.scala | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/library/scala/io/BufferedSource.scala b/src/library/scala/io/BufferedSource.scala index fe66b289e6..5df52d45e3 100644 --- a/src/library/scala/io/BufferedSource.scala +++ b/src/library/scala/io/BufferedSource.scala @@ -6,8 +6,6 @@ ** |/ ** \* */ - - package scala.io import java.io.{ InputStream, BufferedReader, InputStreamReader } @@ -27,5 +25,20 @@ class BufferedSource(inputStream: InputStream, bufferSize: Int)(implicit val cod val reader = bufferedReader() Iterator continually (codec wrap reader.read()) takeWhile (_ != -1) map (_.toChar) } + + class BufferedLineIterator extends Iterator[String] { + val bufReader = BufferedSource.this.bufferedReader() + var nextLine = bufReader.readLine + + override def hasNext() = nextLine != null + + override def next(): String = { + val result = nextLine + nextLine = bufReader.readLine + result + } + } + + override def getLines(): Iterator[String] = new BufferedLineIterator } |