summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/RandomAccessSeq.scala8
-rw-r--r--src/library/scala/Seq.scala6
-rw-r--r--src/library/scala/runtime/RichChar.scala24
3 files changed, 23 insertions, 15 deletions
diff --git a/src/library/scala/RandomAccessSeq.scala b/src/library/scala/RandomAccessSeq.scala
index 437d7ae8fb..363fc72d85 100644
--- a/src/library/scala/RandomAccessSeq.scala
+++ b/src/library/scala/RandomAccessSeq.scala
@@ -13,6 +13,14 @@ package scala
import collection.mutable.ArrayBuffer
object RandomAccessSeq {
+
+ /** The empty sequence */
+ val empty : RandomAccessSeq[Nothing] = new RandomAccessSeq[Nothing] {
+ def length = 0
+ def apply(i: Int): Nothing = throw new NoSuchElementException("empty sequence")
+ override def elements = Iterator.empty
+ }
+
trait Projection[+A] extends Seq.Projection[A] with RandomAccessSeq[A] {
override def projection = this
override def force : RandomAccessSeq[A] = toArray
diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala
index 3b184a1ba5..763a2e8ec2 100644
--- a/src/library/scala/Seq.scala
+++ b/src/library/scala/Seq.scala
@@ -17,11 +17,7 @@ import collection.mutable.ArrayBuffer
object Seq {
/** The empty sequence */
- val empty : Seq[Nothing] = new RandomAccessSeq[Nothing] {
- def length = 0
- def apply(i: Int): Nothing = throw new NoSuchElementException("empty sequence")
- override def elements = Iterator.empty
- }
+ val empty : Seq[Nothing] = RandomAccessSeq.empty
/** This method is called in a pattern match { case Seq(...) => }.
*
diff --git a/src/library/scala/runtime/RichChar.scala b/src/library/scala/runtime/RichChar.scala
index d06aa62a57..52fe17d751 100644
--- a/src/library/scala/runtime/RichChar.scala
+++ b/src/library/scala/runtime/RichChar.scala
@@ -52,20 +52,24 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] {
def toLowerCase: Char = Character.toLowerCase(x)
def toUpperCase: Char = Character.toUpperCase(x)
- /** Create an Iterator[Char] over the characters from 'x' to 'y' - 1
+ /** Create a <code>RandomAccessSeq.Projection[Char]</code> over the characters from 'x' to 'y' - 1
*/
- def until(limit: Char): Iterator[Char] = new Iterator[Char] {
- private var ch = x
- def hasNext: Boolean = ch < limit
- def next: Char =
- if (hasNext) { val j = ch; ch = (ch + 1).toChar; j }
- else throw new NoSuchElementException("next on empty iterator")
- }
+ def until(limit: Char): RandomAccessSeq.Projection[Char] =
+ if (limit <= x) RandomAccessSeq.empty.projection
+ else
+ new RandomAccessSeq.Projection[Char] {
+ def length = limit - x
+ def apply(i: Int): Char = {
+ Predef.require(i >= 0 && i < length)
+ (x + i).toChar
+ }
+ override def stringPrefix = "RandomAccessSeq.Projection"
+ }
//def until(y: Char): Iterator[Char] = to(y)
- /** Create an Iterator[Char] over the characters from 'x' to 'y'
+ /** Create a <code>RandomAccessSeq.Projection[Char]</code> over the characters from 'x' to 'y'
*/
- def to(y: Char): Iterator[Char] = until((y + 1).toChar)
+ def to(y: Char): RandomAccessSeq.Projection[Char] = until((y + 1).toChar)
}