summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2014-12-04 17:28:26 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2014-12-04 17:28:26 +0100
commit083c6657d5d8c0a3a4fad017928a2c1c644d8fb7 (patch)
tree81b42ae308c382c920e674e28a1689420ac08f02 /src
parentb1ae72455e9749df233d8a9f7cea6d486acc8424 (diff)
parent7cf0370ef9e68b60f594143447b753945a8a8780 (diff)
downloadscala-083c6657d5d8c0a3a4fad017928a2c1c644d8fb7.tar.gz
scala-083c6657d5d8c0a3a4fad017928a2c1c644d8fb7.tar.bz2
scala-083c6657d5d8c0a3a4fad017928a2c1c644d8fb7.zip
Merge pull request #4146 from Ichoran/issue/6519
SI-6519 PagedSeq is not lazy enough
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/collection/immutable/PagedSeq.scala8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala
index 3a64820be6..f11217d26a 100644
--- a/src/library/scala/collection/immutable/PagedSeq.scala
+++ b/src/library/scala/collection/immutable/PagedSeq.scala
@@ -158,7 +158,7 @@ extends scala.collection.AbstractSeq[T]
* @note Calling this method will force the entire sequence to be read.
*/
def length: Int = {
- while (!latest.isLast) addMore()
+ while (!latest.isLast && latest.end < end) addMore()
(latest.end min end) - start
}
@@ -175,7 +175,8 @@ extends scala.collection.AbstractSeq[T]
*/
override def isDefinedAt(index: Int) =
index >= 0 && index < end - start && {
- val p = page(index + start); index + start < p.end
+ val absidx = index + start
+ absidx >= 0 && absidx < page(absidx).end
}
/** The subsequence from index `start` up to `end -1` if `end`
@@ -192,6 +193,9 @@ extends scala.collection.AbstractSeq[T]
if (f.next eq null) f.addMore(more)
f = f.next
}
+ // Warning -- not refining `more` means that slices can freely request and obtain
+ // data outside of their slice. This is part of the design of PagedSeq
+ // (to read pages!) but can be surprising.
new PagedSeq(more, f, s, e)
}