summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/collection/TraversableOnce.scala7
-rw-r--r--src/library/scala/collection/TraversableViewLike.scala8
-rw-r--r--src/library/scala/collection/generic/GenericTraversableTemplate.scala2
-rw-r--r--src/library/scala/collection/immutable/MapLike.scala11
-rw-r--r--src/library/scala/collection/immutable/Range.scala4
-rw-r--r--src/library/scala/collection/immutable/SortedMap.scala17
-rw-r--r--src/library/scala/runtime/RichInt.scala8
7 files changed, 43 insertions, 14 deletions
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index 90f1583c58..84fe4bdf4c 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -346,7 +346,12 @@ object TraversableOnce {
}
class FlattenOps[A](travs: TraversableOnce[TraversableOnce[A]]) {
- def flatten: Iterator[A] = travs.foldLeft(Iterator.empty: Iterator[A])(_ ++ _)
+ def flatten: Iterator[A] = new Iterator[A] {
+ val its = travs.toIterator
+ private var it: Iterator[A] = Iterator.empty
+ def hasNext: Boolean = it.hasNext || its.hasNext && { it = its.next.toIterator; hasNext }
+ def next(): A = if (hasNext) it.next() else Iterator.empty.next()
+ }
}
class MonadOps[+A](trav: TraversableOnce[A]) {
diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala
index 6dc0936c61..23e967aea0 100644
--- a/src/library/scala/collection/TraversableViewLike.scala
+++ b/src/library/scala/collection/TraversableViewLike.scala
@@ -16,6 +16,8 @@ import annotation.migration
trait ViewMkString[+A] {
self: Traversable[A] =>
+ // It is necessary to use thisSeq rather than toSeq to avoid cycles in the
+ // eager evaluation of vals in transformed view subclasses, see #4558.
protected[this] def thisSeq: Seq[A] = new ArrayBuffer[A] ++= self result
// Have to overload all three to work around #4299. The overload
@@ -157,17 +159,17 @@ trait TraversableViewLike[+A,
override def splitAt(n: Int): (This, This) = (newTaken(n), newDropped(n))
override def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
- newForced(self.toSeq.scanLeft(z)(op)).asInstanceOf[That]
+ newForced(thisSeq.scanLeft(z)(op)).asInstanceOf[That]
@migration(2, 9,
"This scanRight definition has changed in 2.9.\n" +
"The previous behavior can be reproduced with scanRight.reverse."
)
override def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
- newForced(self.toSeq.scanRight(z)(op)).asInstanceOf[That]
+ newForced(thisSeq.scanRight(z)(op)).asInstanceOf[That]
override def groupBy[K](f: A => K): immutable.Map[K, This] =
- self.toSeq.groupBy(f).mapValues(xs => newForced(xs).asInstanceOf[This])
+ thisSeq.groupBy(f).mapValues(xs => newForced(thisSeq))
override def toString = viewToString
}
diff --git a/src/library/scala/collection/generic/GenericTraversableTemplate.scala b/src/library/scala/collection/generic/GenericTraversableTemplate.scala
index 37d86a0aa9..805009be77 100644
--- a/src/library/scala/collection/generic/GenericTraversableTemplate.scala
+++ b/src/library/scala/collection/generic/GenericTraversableTemplate.scala
@@ -67,7 +67,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNew
*/
def genericBuilder[B]: Builder[B, CC[B]] = companion.newBuilder[B]
- private def sequential: TraversableOnce[A] = this.asInstanceOf[TraversableOnce[A]].seq
+ private def sequential: TraversableOnce[A] = this.asInstanceOf[GenTraversableOnce[A]].seq
/** Converts this $coll of pairs into two collections of the first and second
* half of each pair.
diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala
index fb2826b4df..beea72d676 100644
--- a/src/library/scala/collection/immutable/MapLike.scala
+++ b/src/library/scala/collection/immutable/MapLike.scala
@@ -116,7 +116,16 @@ trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]]
/** Collects all keys of this map in a set.
* @return a set containing all keys of this map.
*/
- override def keySet: immutable.Set[A] = immutable.Set.empty ++ (this map (_._1))
+ override def keySet: immutable.Set[A] = new ImmutableDefaultKeySet
+
+ protected class ImmutableDefaultKeySet extends super.DefaultKeySet with immutable.Set[A] {
+ override def + (elem: A): immutable.Set[A] =
+ if (this(elem)) this
+ else immutable.Set[A]() ++ this + elem
+ override def - (elem: A): immutable.Set[A] =
+ if (this(elem)) immutable.Set[A]() ++ this - elem
+ else this
+ }
/** This function transforms all the values of mappings contained
* in this map with function `f`.
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala
index ef0f08bcfb..b22998fb4b 100644
--- a/src/library/scala/collection/immutable/Range.scala
+++ b/src/library/scala/collection/immutable/Range.scala
@@ -330,7 +330,7 @@ object Range {
@deprecated("use Range instead", "2.9.0")
trait ByOne extends Range {
- @bridge override def foreach[@specialized(Unit) U](f: Int => U) =
- super.foreach(f)
+// @bridge override def foreach[@specialized(Unit) U](f: Int => U) =
+// super.foreach(f)
}
}
diff --git a/src/library/scala/collection/immutable/SortedMap.scala b/src/library/scala/collection/immutable/SortedMap.scala
index f7e05fef69..902a0f8457 100644
--- a/src/library/scala/collection/immutable/SortedMap.scala
+++ b/src/library/scala/collection/immutable/SortedMap.scala
@@ -31,14 +31,27 @@ import annotation.bridge
trait SortedMap[A, +B] extends Map[A, B]
with scala.collection.SortedMap[A, B]
with MapLike[A, B, SortedMap[A, B]]
- with SortedMapLike[A, B, SortedMap[A, B]] {
+ with SortedMapLike[A, B, SortedMap[A, B]] { self =>
override protected[this] def newBuilder : Builder[(A, B), SortedMap[A, B]] =
SortedMap.newBuilder[A, B]
override def empty: SortedMap[A, B] = SortedMap.empty
override def updated [B1 >: B](key: A, value: B1): SortedMap[A, B1] = this + ((key, value))
- override def keySet: immutable.SortedSet[A] = SortedSet.empty ++ (this map (_._1))
+ override def keySet: immutable.SortedSet[A] = new DefaultKeySortedSet
+
+ protected class DefaultKeySortedSet extends super.DefaultKeySortedSet with immutable.SortedSet[A] {
+ override def + (elem: A): SortedSet[A] =
+ if (this(elem)) this
+ else SortedSet[A]() ++ this + elem
+ override def - (elem: A): SortedSet[A] =
+ if (this(elem)) SortedSet[A]() ++ this - elem
+ else this
+ override def rangeImpl(from : Option[A], until : Option[A]) : SortedSet[A] = {
+ val map = self.rangeImpl(from, until)
+ new map.DefaultKeySortedSet
+ }
+ }
/** Add a key/value pair to this map.
* @param kv the key/value pair
diff --git a/src/library/scala/runtime/RichInt.scala b/src/library/scala/runtime/RichInt.scala
index cb02b6d3a8..c1439669f8 100644
--- a/src/library/scala/runtime/RichInt.scala
+++ b/src/library/scala/runtime/RichInt.scala
@@ -21,15 +21,15 @@ final class RichInt(val self: Int) extends ScalaNumberProxy[Int] with RangedProx
def until(end: Int): Range = Range(self, end)
def until(end: Int, step: Int): Range = Range(self, end, step)
- @bridge
- def until(end: Int): Range with Range.ByOne = new Range(self, end, 1) with Range.ByOne
+// @bridge
+// def until(end: Int): Range with Range.ByOne = new Range(self, end, 1) with Range.ByOne
/** like `until`, but includes the last index */
def to(end: Int): Range.Inclusive = Range.inclusive(self, end)
def to(end: Int, step: Int): Range.Inclusive = Range.inclusive(self, end, step)
- @bridge
- def to(end: Int): Range with Range.ByOne = new Range.Inclusive(self, end, 1) with Range.ByOne
+// @bridge
+// def to(end: Int): Range with Range.ByOne = new Range.Inclusive(self, end, 1) with Range.ByOne
override def min(that: Int): Int = if (self < that) self else that
override def max(that: Int): Int = if (self > that) self else that