diff options
author | Paul Phillips <paulp@improving.org> | 2011-11-07 18:22:42 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-11-07 18:22:42 +0000 |
commit | a0a045f5c0b5aa6ed02c849c4ab013cfbfd4e24f (patch) | |
tree | e6a16b89ef2744e86222e53f34e83baf32a1d52d /src/library/scala/collection/immutable | |
parent | 838a09f2a9e0c90df4c2d34832e758ae47ce26cd (diff) | |
download | scala-a0a045f5c0b5aa6ed02c849c4ab013cfbfd4e24f.tar.gz scala-a0a045f5c0b5aa6ed02c849c4ab013cfbfd4e24f.tar.bz2 scala-a0a045f5c0b5aa6ed02c849c4ab013cfbfd4e24f.zip |
Dropped about 1.5 Mb off scala-library.jar.
This commit and the two subsequent commits were contributed by:
Todd Vierling <tv@duh.org>.
I combined some commits and mangled his commit messages, but all the
credit is his. This pursues the same approach to classfile reduction
seen in r19989 when AbstractFunctionN was introduced, but applies it to
the collections. Thanks to -Xlint it's easy to verify that the private
types don't escape.
Design considerations as articulated by Todd:
* Don't necessarily create concrete types for _everything_. Where a
subtrait only provides a few additional methods, don't bother; instead,
use the supertrait's concrete class and retain the "with". For example,
"extends AbstractSeq[A] with LinearSeq[A]".
* Examine all classes with .class file size greater than 10k. Named
classes and class names ending in $$anon$<num> are candidates for
analysis.
* If a return type is currently inferred where an anon subclass would be
returned, make the return type explicit. Don't allow the library-private
abstract classes to leak into the public namespace [and scaladoc].
Diffstat (limited to 'src/library/scala/collection/immutable')
24 files changed, 86 insertions, 55 deletions
diff --git a/src/library/scala/collection/immutable/BitSet.scala b/src/library/scala/collection/immutable/BitSet.scala index bc82c4c133..36aa087dd0 100644 --- a/src/library/scala/collection/immutable/BitSet.scala +++ b/src/library/scala/collection/immutable/BitSet.scala @@ -21,7 +21,8 @@ import mutable.{ Builder, SetBuilder } * @define coll immutable bitset */ @SerialVersionUID(1611436763290191562L) -abstract class BitSet extends Set[Int] +abstract class BitSet extends scala.collection.AbstractSet[Int] + with Set[Int] with scala.collection.BitSet with BitSetLike[BitSet] with Serializable { diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index f4e9c91733..79ee067d63 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -31,7 +31,8 @@ import parallel.immutable.ParHashMap * @define willNotTerminateInf */ @SerialVersionUID(2L) -class HashMap[A, +B] extends Map[A,B] +class HashMap[A, +B] extends AbstractMap[A, B] + with Map[A, B] with MapLike[A, B, HashMap[A, B]] with Serializable with CustomParallelizable[(A, B), ParHashMap[A, B]] diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 579edc66cc..8cb19d4f31 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -30,7 +30,8 @@ import collection.parallel.immutable.ParHashSet * @define coll immutable hash set */ @SerialVersionUID(2L) -class HashSet[A] extends Set[A] +class HashSet[A] extends AbstractSet[A] + with Set[A] with GenericSetTemplate[A, HashSet] with SetLike[A, HashSet[A]] with CustomParallelizable[A, ParHashSet[A]] diff --git a/src/library/scala/collection/immutable/IndexedSeq.scala b/src/library/scala/collection/immutable/IndexedSeq.scala index 2b06c950fa..35b93860a3 100644 --- a/src/library/scala/collection/immutable/IndexedSeq.scala +++ b/src/library/scala/collection/immutable/IndexedSeq.scala @@ -31,7 +31,7 @@ trait IndexedSeq[+A] extends Seq[A] * @define Coll IndexedSeq */ object IndexedSeq extends SeqFactory[IndexedSeq] { - class Impl[A](buf: ArrayBuffer[A]) extends IndexedSeq[A] with Serializable { + class Impl[A](buf: ArrayBuffer[A]) extends AbstractSeq[A] with IndexedSeq[A] with Serializable { def length = buf.length def apply(idx: Int) = buf.apply(idx) } diff --git a/src/library/scala/collection/immutable/IntMap.scala b/src/library/scala/collection/immutable/IntMap.scala index cb1065d786..dd6b066878 100644 --- a/src/library/scala/collection/immutable/IntMap.scala +++ b/src/library/scala/collection/immutable/IntMap.scala @@ -83,7 +83,7 @@ object IntMap { import IntMap._ // Iterator over a non-empty IntMap. -private[immutable] abstract class IntMapIterator[V, T](it : IntMap[V]) extends Iterator[T]{ +private[immutable] abstract class IntMapIterator[V, T](it : IntMap[V]) extends AbstractIterator[T] { // Basically this uses a simple stack to emulate conversion over the tree. However // because we know that Ints are at least 32 bits we can have at most 32 IntMap.Bins and @@ -155,7 +155,11 @@ import IntMap._ * @define mayNotTerminateInf * @define willNotTerminateInf */ -sealed abstract class IntMap[+T] extends Map[Int, T] with MapLike[Int, T, IntMap[T]] { +sealed abstract class IntMap[+T] +extends AbstractMap[Int, T] + with Map[Int, T] + with MapLike[Int, T, IntMap[T]] { + override def empty: IntMap[T] = IntMap.Nil; override def toList = { diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index fb7808bc41..d5e5f2aee0 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -74,7 +74,8 @@ import annotation.tailrec * @define mayNotTerminateInf * @define willNotTerminateInf */ -sealed abstract class List[+A] extends LinearSeq[A] +sealed abstract class List[+A] extends AbstractSeq[A] + with LinearSeq[A] with Product with GenericTraversableTemplate[A, List] with LinearSeqOptimized[A, List[A]] { diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 0933ef7c58..3b7da3259e 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -45,7 +45,11 @@ object ListMap extends ImmutableMapFactory[ListMap] { * @define willNotTerminateInf */ @SerialVersionUID(301002838095710379L) -class ListMap[A, +B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] with Serializable { +class ListMap[A, +B] +extends AbstractMap[A, B] + with Map[A, B] + with MapLike[A, B, ListMap[A, B]] + with Serializable { override def empty = ListMap.empty @@ -112,7 +116,7 @@ class ListMap[A, +B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] with Se /** Returns an iterator over key-value pairs. */ def iterator: Iterator[(A,B)] = - new Iterator[(A,B)] { + new AbstractIterator[(A,B)] { var self: ListMap[A,B] = ListMap.this def hasNext = !self.isEmpty def next(): (A,B) = diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 22e614dd75..47e3245117 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -63,7 +63,8 @@ object ListSet extends ImmutableSetFactory[ListSet] { * @define mayNotTerminateInf * @define willNotTerminateInf */ -class ListSet[A] extends Set[A] +class ListSet[A] extends AbstractSet[A] + with Set[A] with GenericSetTemplate[A, ListSet] with SetLike[A, ListSet[A]] with Serializable{ self => @@ -112,7 +113,7 @@ class ListSet[A] extends Set[A] * @throws Predef.NoSuchElementException * @return the new iterator */ - def iterator: Iterator[A] = new Iterator[A] { + def iterator: Iterator[A] = new AbstractIterator[A] { var that: ListSet[A] = self def hasNext = that.nonEmpty def next: A = diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala index 6c951a6ff2..963ddac762 100644 --- a/src/library/scala/collection/immutable/LongMap.scala +++ b/src/library/scala/collection/immutable/LongMap.scala @@ -79,7 +79,7 @@ object LongMap { import LongMap._ // Iterator over a non-empty LongMap. -private[immutable] abstract class LongMapIterator[V, T](it : LongMap[V]) extends Iterator[T]{ +private[immutable] abstract class LongMapIterator[V, T](it : LongMap[V]) extends AbstractIterator[T] { // Basically this uses a simple stack to emulate conversion over the tree. However // because we know that Longs are only 64 bits we can have at most 64 LongMap.Bins and @@ -152,7 +152,11 @@ import LongMap._; * @define mayNotTerminateInf * @define willNotTerminateInf */ -sealed abstract class LongMap[+T] extends Map[Long, T] with MapLike[Long, T, LongMap[T]] { +sealed abstract class LongMap[+T] +extends AbstractMap[Long, T] + with Map[Long, T] + with MapLike[Long, T, LongMap[T]] { + override def empty: LongMap[T] = LongMap.Nil; override def toList = { diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala index 82cf050f43..45cf088dd9 100644 --- a/src/library/scala/collection/immutable/Map.scala +++ b/src/library/scala/collection/immutable/Map.scala @@ -84,7 +84,7 @@ object Map extends ImmutableMapFactory[Map] { override def withDefaultValue[B1 >: B](d: B1): immutable.Map[A, B1] = new WithDefault[A, B1](underlying, x => d) } - private object EmptyMap extends Map[Any, Nothing] with Serializable { + private object EmptyMap extends AbstractMap[Any, Nothing] with Map[Any, Nothing] with Serializable { override def size: Int = 0 def get(key: Any): Option[Nothing] = None def iterator: Iterator[(Any, Nothing)] = Iterator.empty @@ -93,7 +93,7 @@ object Map extends ImmutableMapFactory[Map] { def - (key: Any): Map[Any, Nothing] = this } - class Map1[A, +B](key1: A, value1: B) extends Map[A, B] with Serializable { + class Map1[A, +B](key1: A, value1: B) extends AbstractMap[A, B] with Map[A, B] with Serializable { override def size = 1 def get(key: A): Option[B] = if (key == key1) Some(value1) else None @@ -109,7 +109,7 @@ object Map extends ImmutableMapFactory[Map] { } } - class Map2[A, +B](key1: A, value1: B, key2: A, value2: B) extends Map[A, B] with Serializable { + class Map2[A, +B](key1: A, value1: B, key2: A, value2: B) extends AbstractMap[A, B] with Map[A, B] with Serializable { override def size = 2 def get(key: A): Option[B] = if (key == key1) Some(value1) @@ -130,7 +130,7 @@ object Map extends ImmutableMapFactory[Map] { } } - class Map3[A, +B](key1: A, value1: B, key2: A, value2: B, key3: A, value3: B) extends Map[A, B] with Serializable { + class Map3[A, +B](key1: A, value1: B, key2: A, value2: B, key3: A, value3: B) extends AbstractMap[A, B] with Map[A, B] with Serializable { override def size = 3 def get(key: A): Option[B] = if (key == key1) Some(value1) @@ -154,7 +154,7 @@ object Map extends ImmutableMapFactory[Map] { } } - class Map4[A, +B](key1: A, value1: B, key2: A, value2: B, key3: A, value3: B, key4: A, value4: B) extends Map[A, B] with Serializable { + class Map4[A, +B](key1: A, value1: B, key2: A, value2: B, key3: A, value3: B, key4: A, value4: B) extends AbstractMap[A, B] with Map[A, B] with Serializable { override def size = 4 def get(key: A): Option[B] = if (key == key1) Some(value1) @@ -182,3 +182,5 @@ object Map extends ImmutableMapFactory[Map] { } } +/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */ +private[scala] abstract class AbstractMap[A, +B] extends scala.collection.AbstractMap[A, B] with Map[A, B] diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala index beea72d676..80da1ab010 100644 --- a/src/library/scala/collection/immutable/MapLike.scala +++ b/src/library/scala/collection/immutable/MapLike.scala @@ -93,7 +93,7 @@ trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] * @return an immutable map consisting only of those key value pairs of this map where the key satisfies * the predicate `p`. The resulting map wraps the original map without copying any elements. */ - override def filterKeys(p: A => Boolean): Map[A, B] = new DefaultMap[A, B] { + override def filterKeys(p: A => Boolean): Map[A, B] = new AbstractMap[A, B] with DefaultMap[A, B] { override def foreach[C](f: ((A, B)) => C): Unit = for (kv <- self) if (p(kv._1)) f(kv) def iterator = self.iterator.filter(kv => p(kv._1)) override def contains(key: A) = self.contains(key) && p(key) @@ -105,7 +105,7 @@ trait MapLike[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] * @return a map view which maps every key of this map * to `f(this(key))`. The resulting map wraps the original map without copying any elements. */ - override def mapValues[C](f: B => C): Map[A, C] = new DefaultMap[A, C] { + override def mapValues[C](f: B => C): Map[A, C] = new AbstractMap[A, C] with DefaultMap[A, C] { override def foreach[D](g: ((A, C)) => D): Unit = for ((k, v) <- self) g((k, f(v))) def iterator = for ((k, v) <- self.iterator) yield (k, f(v)) override def size = self.size diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala index e70db13251..65bd9ab6f2 100644 --- a/src/library/scala/collection/immutable/NumericRange.scala +++ b/src/library/scala/collection/immutable/NumericRange.scala @@ -42,7 +42,7 @@ import generic._ abstract class NumericRange[T] (val start: T, val end: T, val step: T, val isInclusive: Boolean) (implicit num: Integral[T]) -extends IndexedSeq[T] with Serializable { +extends AbstractSeq[T] with IndexedSeq[T] with Serializable { /** Note that NumericRange must be invariant so that constructs * such as "1L to 10 by 5" do not infer the range type as AnyVal. */ diff --git a/src/library/scala/collection/immutable/PagedSeq.scala b/src/library/scala/collection/immutable/PagedSeq.scala index 8e14d9885d..97c7c789f8 100644 --- a/src/library/scala/collection/immutable/PagedSeq.scala +++ b/src/library/scala/collection/immutable/PagedSeq.scala @@ -129,7 +129,8 @@ class PagedSeq[T: ClassManifest] protected( first1: Page[T], start: Int, end: Int) -extends scala.collection.IndexedSeq[T] +extends scala.collection.AbstractSeq[T] + with scala.collection.IndexedSeq[T] { def this(more: (Array[T], Int, Int) => Int) = this(more, new Page[T](0), 0, UndeterminedEnd) diff --git a/src/library/scala/collection/immutable/Queue.scala b/src/library/scala/collection/immutable/Queue.scala index c1db8b4851..6e73eef101 100644 --- a/src/library/scala/collection/immutable/Queue.scala +++ b/src/library/scala/collection/immutable/Queue.scala @@ -35,7 +35,8 @@ import annotation.tailrec @SerialVersionUID(-7622936493364270175L) class Queue[+A] protected(protected val in: List[A], protected val out: List[A]) - extends LinearSeq[A] + extends AbstractSeq[A] + with LinearSeq[A] with GenericTraversableTemplate[A, Queue] with LinearSeqLike[A, Queue[A]] with Serializable { diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala index 804c67527a..47ce2f0341 100644 --- a/src/library/scala/collection/immutable/Range.scala +++ b/src/library/scala/collection/immutable/Range.scala @@ -41,7 +41,8 @@ import annotation.bridge */ @SerialVersionUID(7618862778670199309L) class Range(val start: Int, val end: Int, val step: Int) -extends IndexedSeq[Int] +extends collection.AbstractSeq[Int] + with IndexedSeq[Int] with collection.CustomParallelizable[Int, ParRange] with Serializable { diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala index 89be64b1d2..fe3ce8fd0b 100644 --- a/src/library/scala/collection/immutable/Set.scala +++ b/src/library/scala/collection/immutable/Set.scala @@ -49,7 +49,7 @@ object Set extends ImmutableSetFactory[Set] { private val hashSeed = "Set".hashCode /** An optimized representation for immutable empty sets */ - private object EmptySet extends Set[Any] with Serializable { + private object EmptySet extends AbstractSet[Any] with Set[Any] with Serializable { override def size: Int = 0 def contains(elem: Any): Boolean = false def + (elem: Any): Set[Any] = new Set1(elem) @@ -60,7 +60,7 @@ object Set extends ImmutableSetFactory[Set] { /** An optimized representation for immutable sets of size 1 */ @SerialVersionUID(1233385750652442003L) - class Set1[A] private[collection] (elem1: A) extends Set[A] with Serializable { + class Set1[A] private[collection] (elem1: A) extends AbstractSet[A] with Set[A] with Serializable { override def size: Int = 1 def contains(elem: A): Boolean = elem == elem1 @@ -79,7 +79,7 @@ object Set extends ImmutableSetFactory[Set] { /** An optimized representation for immutable sets of size 2 */ @SerialVersionUID(-6443011234944830092L) - class Set2[A] private[collection] (elem1: A, elem2: A) extends Set[A] with Serializable { + class Set2[A] private[collection] (elem1: A, elem2: A) extends AbstractSet[A] with Set[A] with Serializable { override def size: Int = 2 def contains(elem: A): Boolean = elem == elem1 || elem == elem2 @@ -99,7 +99,7 @@ object Set extends ImmutableSetFactory[Set] { /** An optimized representation for immutable sets of size 3 */ @SerialVersionUID(-3590273538119220064L) - class Set3[A] private[collection] (elem1: A, elem2: A, elem3: A) extends Set[A] with Serializable { + class Set3[A] private[collection] (elem1: A, elem2: A, elem3: A) extends AbstractSet[A] with Set[A] with Serializable { override def size: Int = 3 def contains(elem: A): Boolean = elem == elem1 || elem == elem2 || elem == elem3 @@ -120,7 +120,7 @@ object Set extends ImmutableSetFactory[Set] { /** An optimized representation for immutable sets of size 4 */ @SerialVersionUID(-3622399588156184395L) - class Set4[A] private[collection] (elem1: A, elem2: A, elem3: A, elem4: A) extends Set[A] with Serializable { + class Set4[A] private[collection] (elem1: A, elem2: A, elem3: A, elem4: A) extends AbstractSet[A] with Set[A] with Serializable { override def size: Int = 4 def contains(elem: A): Boolean = elem == elem1 || elem == elem2 || elem == elem3 || elem == elem4 diff --git a/src/library/scala/collection/immutable/SetProxy.scala b/src/library/scala/collection/immutable/SetProxy.scala index 9c1e2f0b4d..3c098061f0 100644 --- a/src/library/scala/collection/immutable/SetProxy.scala +++ b/src/library/scala/collection/immutable/SetProxy.scala @@ -24,7 +24,7 @@ package immutable trait SetProxy[A] extends Set[A] with SetProxyLike[A, Set[A]] { override def repr = this private def newProxy[B >: A](newSelf: Set[B]): SetProxy[B] = - new SetProxy[B] { val self = newSelf } + new AbstractSet[B] with SetProxy[B] { val self = newSelf } override def empty = newProxy(self.empty) override def + (elem: A) = newProxy(self + elem) diff --git a/src/library/scala/collection/immutable/Stack.scala b/src/library/scala/collection/immutable/Stack.scala index 238b3e414f..d65300ecb7 100644 --- a/src/library/scala/collection/immutable/Stack.scala +++ b/src/library/scala/collection/immutable/Stack.scala @@ -43,7 +43,8 @@ object Stack extends SeqFactory[Stack] { */ @SerialVersionUID(1976480595012942526L) class Stack[+A] protected (protected val elems: List[A]) - extends LinearSeq[A] + extends AbstractSeq[A] + with LinearSeq[A] with GenericTraversableTemplate[A, Stack] with LinearSeqOptimized[A, Stack[A]] with Serializable { diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 7fa973e82f..7bae387ad2 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -178,7 +178,8 @@ import Stream.cons * @define orderDependent * @define orderDependentFold */ -abstract class Stream[+A] extends LinearSeq[A] +abstract class Stream[+A] extends AbstractSeq[A] + with LinearSeq[A] with GenericTraversableTemplate[A, Stream] with LinearSeqOptimized[A, Stream[A]] { self => @@ -925,7 +926,7 @@ self => /** A specialized, extra-lazy implementation of a stream iterator, so it can * iterate as lazily as it traverses the tail. */ -final class StreamIterator[+A](self: Stream[A]) extends Iterator[A] { +final class StreamIterator[+A](self: Stream[A]) extends AbstractIterator[A] with Iterator[A] { // A call-by-need cell. class LazyCell(st: => Stream[A]) { lazy val v = st diff --git a/src/library/scala/collection/immutable/StreamViewLike.scala b/src/library/scala/collection/immutable/StreamViewLike.scala index 7c44c1e019..3fd92aaff9 100644 --- a/src/library/scala/collection/immutable/StreamViewLike.scala +++ b/src/library/scala/collection/immutable/StreamViewLike.scala @@ -18,11 +18,14 @@ extends SeqView[A, Coll] override def toString = viewToString } - trait EmptyView extends Transformed[Nothing] with super.EmptyView { } + /** Explicit instantiation of the `Transformed` trait to reduce class file size in subclasses. */ + private[collection] abstract class AbstractTransformed[+B] extends super.AbstractTransformed[B] with Transformed[B] - trait Forced[B] extends super.Forced[B] with Transformed[B] { } + trait EmptyView extends Transformed[Nothing] with super.EmptyView - trait Sliced extends super.Sliced with Transformed[A] { } + trait Forced[B] extends super.Forced[B] with Transformed[B] + + trait Sliced extends super.Sliced with Transformed[A] trait Mapped[B] extends super.Mapped[B] with Transformed[B] @@ -47,23 +50,23 @@ extends SeqView[A, Coll] trait Prepended[B >: A] extends super.Prepended[B] with Transformed[B] /** boilerplate */ - protected override def newForced[B](xs: => collection.GenSeq[B]): Transformed[B] = new { val forced = xs } with Forced[B] - protected override def newAppended[B >: A](that: collection.GenTraversable[B]): Transformed[B] = new { val rest = that } with Appended[B] - protected override def newMapped[B](f: A => B): Transformed[B] = new { val mapping = f } with Mapped[B] - protected override def newFlatMapped[B](f: A => collection.GenTraversableOnce[B]): Transformed[B] = new { val mapping = f } with FlatMapped[B] - protected override def newFiltered(p: A => Boolean): Transformed[A] = new { val pred = p } with Filtered - protected override def newSliced(_endpoints: SliceInterval): Transformed[A] = new { val endpoints = _endpoints } with Sliced - protected override def newDroppedWhile(p: A => Boolean): Transformed[A] = new { val pred = p } with DroppedWhile - protected override def newTakenWhile(p: A => Boolean): Transformed[A] = new { val pred = p } with TakenWhile - protected override def newZipped[B](that: collection.GenIterable[B]): Transformed[(A, B)] = new { val other = that } with Zipped[B] + protected override def newForced[B](xs: => collection.GenSeq[B]): Transformed[B] = new { val forced = xs } with AbstractTransformed[B] with Forced[B] + protected override def newAppended[B >: A](that: collection.GenTraversable[B]): Transformed[B] = new { val rest = that } with AbstractTransformed[B] with Appended[B] + protected override def newMapped[B](f: A => B): Transformed[B] = new { val mapping = f } with AbstractTransformed[B] with Mapped[B] + protected override def newFlatMapped[B](f: A => collection.GenTraversableOnce[B]): Transformed[B] = new { val mapping = f } with AbstractTransformed[B] with FlatMapped[B] + protected override def newFiltered(p: A => Boolean): Transformed[A] = new { val pred = p } with AbstractTransformed[A] with Filtered + protected override def newSliced(_endpoints: SliceInterval): Transformed[A] = new { val endpoints = _endpoints } with AbstractTransformed[A] with Sliced + protected override def newDroppedWhile(p: A => Boolean): Transformed[A] = new { val pred = p } with AbstractTransformed[A] with DroppedWhile + protected override def newTakenWhile(p: A => Boolean): Transformed[A] = new { val pred = p } with AbstractTransformed[A] with TakenWhile + protected override def newZipped[B](that: collection.GenIterable[B]): Transformed[(A, B)] = new { val other = that } with AbstractTransformed[(A, B)] with Zipped[B] protected override def newZippedAll[A1 >: A, B](that: collection.GenIterable[B], _thisElem: A1, _thatElem: B): Transformed[(A1, B)] = { - new { val other = that; val thisElem = _thisElem; val thatElem = _thatElem } with ZippedAll[A1, B] + new { val other = that; val thisElem = _thisElem; val thatElem = _thatElem } with AbstractTransformed[(A1, B)] with ZippedAll[A1, B] } protected override def newReversed: Transformed[A] = new Reversed { } protected override def newPatched[B >: A](_from: Int, _patch: collection.GenSeq[B], _replaced: Int): Transformed[B] = { - new { val from = _from; val patch = _patch; val replaced = _replaced } with Patched[B] + new { val from = _from; val patch = _patch; val replaced = _replaced } with AbstractTransformed[B] with Patched[B] } - protected override def newPrepended[B >: A](elem: B): Transformed[B] = new { protected[this] val fst = elem } with Prepended[B] + protected override def newPrepended[B >: A](elem: B): Transformed[B] = new { protected[this] val fst = elem } with AbstractTransformed[B] with Prepended[B] override def stringPrefix = "StreamView" } diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index 42ac5bb23b..9b52c8805c 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -106,7 +106,7 @@ self => * - `LF` - line feed (`0x0A` hex) * - `FF` - form feed (`0x0C` hex) */ - def linesWithSeparators: Iterator[String] = new Iterator[String] { + def linesWithSeparators: Iterator[String] = new AbstractIterator[String] { val str = self.toString private val len = str.length private var index = 0 diff --git a/src/library/scala/collection/immutable/TrieIterator.scala b/src/library/scala/collection/immutable/TrieIterator.scala index 7c36ed14ce..c77334b732 100644 --- a/src/library/scala/collection/immutable/TrieIterator.scala +++ b/src/library/scala/collection/immutable/TrieIterator.scala @@ -17,7 +17,7 @@ import scala.annotation.tailrec /** Abandons any pretense of type safety for speed. You can't say I * didn't try: see r23934. */ -private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) extends Iterator[T] { +private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) extends AbstractIterator[T] { outer => private[immutable] def getElem(x: AnyRef): T @@ -216,4 +216,4 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e } } } -}
\ No newline at end of file +} diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index 5c8046fa58..ab12300097 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -52,7 +52,8 @@ object Vector extends SeqFactory[Vector] { * @define willNotTerminateInf */ final class Vector[+A](private[collection] val startIndex: Int, private[collection] val endIndex: Int, focus: Int) -extends IndexedSeq[A] +extends AbstractSeq[A] + with IndexedSeq[A] with GenericTraversableTemplate[A, Vector] with IndexedSeqLike[A, Vector[A]] with VectorPointer[A @uncheckedVariance] @@ -90,7 +91,7 @@ override def companion: GenericCompanion[Vector] = Vector // can still be improved override /*SeqLike*/ - def reverseIterator: Iterator[A] = new Iterator[A] { + def reverseIterator: Iterator[A] = new AbstractIterator[A] { private var i = self.length def hasNext: Boolean = 0 < i def next(): A = @@ -636,7 +637,10 @@ override def companion: GenericCompanion[Vector] = Vector } -class VectorIterator[+A](_startIndex: Int, _endIndex: Int) extends Iterator[A] with VectorPointer[A @uncheckedVariance] { +class VectorIterator[+A](_startIndex: Int, _endIndex: Int) +extends AbstractIterator[A] + with Iterator[A] + with VectorPointer[A @uncheckedVariance] { private var blockIndex: Int = _startIndex & ~31 private var lo: Int = _startIndex & 31 diff --git a/src/library/scala/collection/immutable/WrappedString.scala b/src/library/scala/collection/immutable/WrappedString.scala index b6fd98fd0e..de8aeea7e1 100644 --- a/src/library/scala/collection/immutable/WrappedString.scala +++ b/src/library/scala/collection/immutable/WrappedString.scala @@ -28,7 +28,7 @@ import mutable.{Builder, StringBuilder} * @define Coll WrappedString * @define coll wrapped string */ -class WrappedString(val self: String) extends IndexedSeq[Char] with StringLike[WrappedString] { +class WrappedString(val self: String) extends AbstractSeq[Char] with IndexedSeq[Char] with StringLike[WrappedString] { override protected[this] def thisCollection: WrappedString = this override protected[this] def toCollection(repr: WrappedString): WrappedString = repr |