summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/MapLike.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-11-07 18:22:42 +0000
committerPaul Phillips <paulp@improving.org>2011-11-07 18:22:42 +0000
commita0a045f5c0b5aa6ed02c849c4ab013cfbfd4e24f (patch)
treee6a16b89ef2744e86222e53f34e83baf32a1d52d /src/library/scala/collection/MapLike.scala
parent838a09f2a9e0c90df4c2d34832e758ae47ce26cd (diff)
downloadscala-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/MapLike.scala')
-rw-r--r--src/library/scala/collection/MapLike.scala12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala
index 5b4ac20329..3485fe1be6 100644
--- a/src/library/scala/collection/MapLike.scala
+++ b/src/library/scala/collection/MapLike.scala
@@ -159,7 +159,7 @@ self =>
/** The implementation class of the set returned by `keySet`.
*/
- protected class DefaultKeySet extends Set[A] {
+ protected class DefaultKeySet extends AbstractSet[A] {
def contains(key : A) = self.contains(key)
def iterator = keysIterator
def + (elem: A): Set[A] = (Set[A]() ++ this + elem).asInstanceOf[Set[A]] // !!! concrete overrides abstract problem
@@ -172,7 +172,7 @@ self =>
*
* @return an iterator over all keys.
*/
- def keysIterator: Iterator[A] = new Iterator[A] {
+ def keysIterator: Iterator[A] = new AbstractIterator[A] {
val iter = self.iterator
def hasNext = iter.hasNext
def next() = iter.next._1
@@ -194,7 +194,7 @@ self =>
/** The implementation class of the iterable returned by `values`.
*/
- protected class DefaultValuesIterable extends Iterable[B] {
+ protected class DefaultValuesIterable extends AbstractIterable[B] {
def iterator = valuesIterator
override def size = self.size
override def foreach[C](f: B => C) = self.valuesIterator foreach f
@@ -204,7 +204,7 @@ self =>
*
* @return an iterator over all values that are associated with some key in this map.
*/
- def valuesIterator: Iterator[B] = new Iterator[B] {
+ def valuesIterator: Iterator[B] = new AbstractIterator[B] {
val iter = self.iterator
def hasNext = iter.hasNext
def next() = iter.next._2
@@ -226,7 +226,7 @@ self =>
* @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.
*/
- def filterKeys(p: A => Boolean): Map[A, B] = new DefaultMap[A, B] {
+ 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)
@@ -238,7 +238,7 @@ self =>
* @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.
*/
- def mapValues[C](f: B => C): Map[A, C] = new DefaultMap[A, C] {
+ 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