summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/LinearSeqOptimized.scala
diff options
context:
space:
mode:
authorJean-Remi Desjardins <jeanremi.desjardins@gmail.com>2012-11-22 00:59:43 -0500
committerPaul Phillips <paulp@improving.org>2012-12-28 16:56:06 -0800
commit24a033b2aa4174fe8e9c3c02372b6508ef404601 (patch)
tree11576d7d56057ad565af82a0896fb4a41d4d3e36 /src/library/scala/collection/LinearSeqOptimized.scala
parent1284c3c6f38cc419a0a39fd68b3d5cf81b36b1a5 (diff)
downloadscala-24a033b2aa4174fe8e9c3c02372b6508ef404601.tar.gz
scala-24a033b2aa4174fe8e9c3c02372b6508ef404601.tar.bz2
scala-24a033b2aa4174fe8e9c3c02372b6508ef404601.zip
SI-6415, overly eager evaluation in Stream.
The lengthCompare method in LinearSeqOptimized was looking one step further than it needed to in order to give the correct result, which was creating some unwanted side effects related to Streams.
Diffstat (limited to 'src/library/scala/collection/LinearSeqOptimized.scala')
-rwxr-xr-xsrc/library/scala/collection/LinearSeqOptimized.scala20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
index 0f0a405a85..48b0b5469e 100755
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -247,14 +247,20 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
}
override /*SeqLike*/
- def lengthCompare(len: Int): Int = {
- var i = 0
- var these = self
- while (!these.isEmpty && i <= len) {
- i += 1
- these = these.tail
+ def lengthCompare(len: Int): Int = {
+ // TODO: Remove this method when incrementing a major revision
+ // This method is the same as in SeqLike, no need to redefine it
+ if (len < 0) 1
+ else {
+ var i = 0
+ val it = iterator
+ while (it.hasNext) {
+ if (i == len) return if (it.hasNext) 1 else 0
+ it.next()
+ i += 1
+ }
+ i - len
}
- i - len
}
override /*SeqLike*/