summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/LinearSeqOptimized.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-08 15:40:53 +0000
committerPaul Phillips <paulp@improving.org>2011-03-08 15:40:53 +0000
commit783721e98a4f61fc0c72298811b15e99c058d5e6 (patch)
treecdc0786526c572cfb9198942d517fbfd36ed0ba5 /src/library/scala/collection/LinearSeqOptimized.scala
parent8328a880b60ded33d5d49b88bdc75020b577eb27 (diff)
downloadscala-783721e98a4f61fc0c72298811b15e99c058d5e6.tar.gz
scala-783721e98a4f61fc0c72298811b15e99c058d5e6.tar.bz2
scala-783721e98a4f61fc0c72298811b15e99c058d5e6.zip
An overhaul of slice and related implementation...
An overhaul of slice and related implementations (primarily that is drop and take.) In the course of trying to get it working consistently (mostly with respect to negative indices, which were dealt with arbitrarily differently across the 25+ concrete implementations) I fixed various bugs. Closes #4288, no review.
Diffstat (limited to 'src/library/scala/collection/LinearSeqOptimized.scala')
-rwxr-xr-xsrc/library/scala/collection/LinearSeqOptimized.scala16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
index 5e47021110..f57dba2d3f 100755
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -183,13 +183,21 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
override /*IterableLike*/
def slice(from: Int, until: Int): Repr = {
+ var these: Repr = repr
+ var count = from max 0
+ if (until <= count)
+ return newBuilder.result
+
val b = newBuilder
- var i = from
- var these = this drop from
- while (i < until && !these.isEmpty) {
+ var sliceElems = until - count
+ while (these.nonEmpty && count > 0) {
+ these = these.tail
+ count -= 1
+ }
+ while (these.nonEmpty && sliceElems > 0) {
+ sliceElems -= 1
b += these.head
these = these.tail
- i += 1
}
b.result
}