summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/Map.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/immutable/Map.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/immutable/Map.scala')
-rw-r--r--src/library/scala/collection/immutable/Map.scala12
1 files changed, 7 insertions, 5 deletions
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]