summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSeth Tisue <seth@tisue.net>2016-10-26 08:04:57 -0700
committerGitHub <noreply@github.com>2016-10-26 08:04:57 -0700
commitb9a16c4a812a0bde8bd23fb90c0ec5d9439e0e14 (patch)
tree7126fa0326312b37c87a1cc7a65ff0a63129536b /src
parentf66ed4d4f798fa693f87702769252ddfc6b81cf3 (diff)
parent9a6ef0fe508a7ba9692871ee05452c8dbd29888b (diff)
downloadscala-b9a16c4a812a0bde8bd23fb90c0ec5d9439e0e14.tar.gz
scala-b9a16c4a812a0bde8bd23fb90c0ec5d9439e0e14.tar.bz2
scala-b9a16c4a812a0bde8bd23fb90c0ec5d9439e0e14.zip
Merge pull request #5378 from som-snytt/issue/9913
SI-9913 Lead span iterator finishes at state -1
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/Iterator.scala23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 9ba16976bd..03b9fbff26 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -648,15 +648,15 @@ trait Iterator[+A] extends TraversableOnce[A] {
* handling of structural calls. It's not what's intended here.
*/
class Leading extends AbstractIterator[A] {
- var lookahead: mutable.Queue[A] = null
- var hd: A = _
+ private[this] var lookahead: mutable.Queue[A] = null
+ private[this] var hd: A = _
/* Status is kept with magic numbers
* 1 means next element is in hd and we're still reading into this iterator
* 0 means we're still reading but haven't found a next element
* -1 means we are done reading into the iterator, so we must rely on lookahead
* -2 means we are done but have saved hd for the other iterator to use as its first element
*/
- var status = 0
+ private[this] var status = 0
private def store(a: A) {
if (lookahead == null) lookahead = new mutable.Queue[A]
lookahead += a
@@ -680,26 +680,23 @@ trait Iterator[+A] extends TraversableOnce[A] {
}
else empty.next()
}
- def finish(): Boolean = {
- if (status == -1) false
- else if (status == -2) {
+ def finish(): Boolean = status match {
+ case -2 => status = -1 ; true
+ case -1 => false
+ case 1 => store(hd) ; status = 0 ; finish()
+ case 0 =>
status = -1
- true
- }
- else {
- if (status == 1) store(hd)
while (self.hasNext) {
val a = self.next()
if (p(a)) store(a)
else {
hd = a
- status = -1
return true
}
}
false
- }
}
+ def trailer: A = hd
}
val leading = new Leading
@@ -732,7 +729,7 @@ trait Iterator[+A] extends TraversableOnce[A] {
if (status > 0) self.next()
else {
status = 1
- val ans = myLeading.hd
+ val ans = myLeading.trailer
myLeading = null
ans
}