diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-03-20 21:47:46 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-03-20 22:00:52 +0100 |
commit | 1fa46a5a9634f09e4905da2468acf5ea75d6462e (patch) | |
tree | 157c4a5bb237b59090fee56383f9ccafa85dacec /test/files/run/t8428.scala | |
parent | bcf24ec9ba07408ad9e8745135cc941ac3e76289 (diff) | |
download | scala-1fa46a5a9634f09e4905da2468acf5ea75d6462e.tar.gz scala-1fa46a5a9634f09e4905da2468acf5ea75d6462e.tar.bz2 scala-1fa46a5a9634f09e4905da2468acf5ea75d6462e.zip |
SI-8428 Fix regression in iterator concatenation
Regressed in e3ddb2d7, which introduced `ConcatIterator` to
avoid super-linear runtime on chains of concatenated iterators.
`ConcatIterator` maintains a queue of thunks for the remaining
iterators. Both `next` and `hasNext` delegate to `advance`, which
evaluates the thunks and discards any empty iterators from the
start of the queue. The first non-empty iterator is stored in
the var `current`.
It also overrides `++`, and creates a new `ConcatIterator` with
the given `that` as an extra element in the queue. However, it
failed to copy `current` across, which led to data loss.
Diffstat (limited to 'test/files/run/t8428.scala')
-rw-r--r-- | test/files/run/t8428.scala | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/files/run/t8428.scala b/test/files/run/t8428.scala new file mode 100644 index 0000000000..7da1207b7b --- /dev/null +++ b/test/files/run/t8428.scala @@ -0,0 +1,12 @@ +object Test extends App { + val xs = List.tabulate(4)(List(_)) + val i = xs.map(_.iterator).reduce { (a,b) => + a.hasNext + a ++ b + } + + val r1 = i.toList + val r2 = xs.flatten.toList + + assert(r1 == r2, r1) +} |