summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-05-02 14:39:13 -0700
committerPaul Phillips <paulp@improving.org>2012-05-02 18:23:14 -0700
commit6300c3033e7b852c6cbef332af6085aac6150a70 (patch)
tree4a508dc17945e3152c80e27a4a122196e348a5cd /src
parentb6e989fbf63c9f47acfb54175241b42fdfbfe51b (diff)
downloadscala-6300c3033e7b852c6cbef332af6085aac6150a70.tar.gz
scala-6300c3033e7b852c6cbef332af6085aac6150a70.tar.bz2
scala-6300c3033e7b852c6cbef332af6085aac6150a70.zip
Eliminating reflective calls.
Frobbed knobs and made little traits until all relevant looking reflective calls were gone.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/internal/Required.scala5
-rw-r--r--src/compiler/scala/reflect/internal/SymbolTable.scala27
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala7
-rw-r--r--src/compiler/scala/reflect/runtime/AbstractFile.scala11
-rw-r--r--src/compiler/scala/tools/nsc/io/AbstractFile.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/WeakHashSet.scala3
-rw-r--r--src/library/scala/collection/generic/Clearable.scala26
-rw-r--r--src/library/scala/collection/generic/Growable.scala4
-rw-r--r--src/library/scala/reflect/api/RequiredFile.scala7
9 files changed, 62 insertions, 31 deletions
diff --git a/src/compiler/scala/reflect/internal/Required.scala b/src/compiler/scala/reflect/internal/Required.scala
index ba6d65a306..6d146354a3 100644
--- a/src/compiler/scala/reflect/internal/Required.scala
+++ b/src/compiler/scala/reflect/internal/Required.scala
@@ -5,10 +5,7 @@ import settings.MutableSettings
trait Required { self: SymbolTable =>
- type AbstractFileType >: Null <: {
- def path: String
- def canonicalPath: String
- }
+ type AbstractFileType >: Null <: api.RequiredFile
def picklerPhase: Phase
diff --git a/src/compiler/scala/reflect/internal/SymbolTable.scala b/src/compiler/scala/reflect/internal/SymbolTable.scala
index 9158c2a4d4..aa60fb4aba 100644
--- a/src/compiler/scala/reflect/internal/SymbolTable.scala
+++ b/src/compiler/scala/reflect/internal/SymbolTable.scala
@@ -280,16 +280,8 @@ abstract class SymbolTable extends api.Universe
object perRunCaches {
import java.lang.ref.WeakReference
import scala.runtime.ScalaRunTime.stringOf
+ import scala.collection.generic.Clearable
- import language.reflectiveCalls
-
- // We can allow ourselves a structural type, these methods
- // amount to a few calls per run at most. This does suggest
- // a "Clearable" trait may be useful.
- private type Clearable = {
- def size: Int
- def clear(): Unit
- }
// Weak references so the garbage collector will take care of
// letting us know when a cache is really out of commission.
private val caches = mutable.HashSet[WeakReference[Clearable]]()
@@ -298,10 +290,14 @@ abstract class SymbolTable extends api.Universe
println(caches.size + " structures are in perRunCaches.")
caches.zipWithIndex foreach { case (ref, index) =>
val cache = ref.get()
- println("(" + index + ")" + (
- if (cache == null) " has been collected."
- else " has " + cache.size + " entries:\n" + stringOf(cache)
- ))
+ cache match {
+ case xs: Traversable[_] =>
+ println("(" + index + ")" + (
+ if (cache == null) " has been collected."
+ else " has " + xs.size + " entries:\n" + stringOf(xs)
+ ))
+ case _ =>
+ }
}
}
// if (settings.debug.value) {
@@ -315,8 +311,9 @@ abstract class SymbolTable extends api.Universe
def clearAll() = {
if (settings.debug.value) {
- val size = caches flatMap (ref => Option(ref.get)) map (_.size) sum;
- log("Clearing " + caches.size + " caches totalling " + size + " entries.")
+ // val size = caches flatMap (ref => Option(ref.get)) map (_.size) sum;
+ log("Clearing " + caches.size + " caches.")
+ // totalling " + size + " entries.")
}
caches foreach { ref =>
val cache = ref.get()
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index b8346a663d..165f8119ce 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -6,7 +6,8 @@
package scala.reflect
package internal
-import scala.collection.{ mutable, immutable }
+import scala.collection.{ mutable, immutable, generic }
+import generic.Clearable
import scala.ref.WeakReference
import mutable.ListBuffer
import Flags._
@@ -115,7 +116,7 @@ trait Types extends api.Types { self: SymbolTable =>
protected def newUndoLog = new UndoLog
- class UndoLog {
+ class UndoLog extends Clearable {
private type UndoPairs = List[(TypeVar, TypeConstraint)]
private var log: UndoPairs = List()
@@ -139,7 +140,7 @@ trait Types extends api.Types { self: SymbolTable =>
log ::= ((tv, tv.constr.cloneInternal))
}
- private[scala] def clear() {
+ def clear() {
if (settings.debug.value)
self.log("Clearing " + log.size + " entries from the undoLog.")
diff --git a/src/compiler/scala/reflect/runtime/AbstractFile.scala b/src/compiler/scala/reflect/runtime/AbstractFile.scala
index bf3b47298b..414bba020b 100644
--- a/src/compiler/scala/reflect/runtime/AbstractFile.scala
+++ b/src/compiler/scala/reflect/runtime/AbstractFile.scala
@@ -1,6 +1,7 @@
-package scala.reflect.runtime
+package scala.reflect
+package runtime
-class AbstractFile(val jfile: java.io.File) {
- def path: String = jfile.getPath()
- def canonicalPath: String = jfile.getCanonicalPath()
-} \ No newline at end of file
+class AbstractFile(val jfile: java.io.File) extends api.RequiredFile {
+ def path: String = jfile.getPath()
+ def canonicalPath: String = jfile.getCanonicalPath()
+}
diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala
index b51cf1228c..deb914f806 100644
--- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala
+++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala
@@ -10,6 +10,7 @@ package io
import java.io.{ FileOutputStream, IOException, InputStream, OutputStream, BufferedOutputStream }
import java.net.URL
import scala.collection.mutable.ArrayBuffer
+import scala.reflect.api.RequiredFile
/**
* @author Philippe Altherr
@@ -81,7 +82,7 @@ object AbstractFile {
* <code>global.settings.encoding.value</code>.
* </p>
*/
-abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
+abstract class AbstractFile extends AnyRef with RequiredFile with Iterable[AbstractFile] {
/** Returns the name of this abstract file. */
def name: String
diff --git a/src/compiler/scala/tools/nsc/util/WeakHashSet.scala b/src/compiler/scala/tools/nsc/util/WeakHashSet.scala
index 6a10422b00..5bbb766e21 100644
--- a/src/compiler/scala/tools/nsc/util/WeakHashSet.scala
+++ b/src/compiler/scala/tools/nsc/util/WeakHashSet.scala
@@ -4,6 +4,7 @@ import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.Builder
import scala.collection.mutable.SetBuilder
+import scala.collection.generic.Clearable
import scala.runtime.AbstractFunction1
/** A bare-bones implementation of a mutable `Set` that uses weak references
@@ -12,7 +13,7 @@ import scala.runtime.AbstractFunction1
* This implementation offers only add/remove/test operations,
* therefore it does not fulfill the contract of Scala collection sets.
*/
-class WeakHashSet[T <: AnyRef] extends AbstractFunction1[T, Boolean] {
+class WeakHashSet[T <: AnyRef] extends AbstractFunction1[T, Boolean] with Clearable {
private val underlying = mutable.HashSet[WeakReferenceWithEquals[T]]()
/** Add the given element to this set. */
diff --git a/src/library/scala/collection/generic/Clearable.scala b/src/library/scala/collection/generic/Clearable.scala
new file mode 100644
index 0000000000..6c8d9558b0
--- /dev/null
+++ b/src/library/scala/collection/generic/Clearable.scala
@@ -0,0 +1,26 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.collection
+package generic
+
+/** This trait forms part of collections that can be cleared
+ * with a clear() call.
+ *
+ * @author Paul Phillips
+ * @version 2.10
+ * @since 2.10
+ * @define coll clearable collection
+ * @define Coll `Clearable`
+ */
+trait Clearable {
+ /** Clears the $coll's contents. After this operation, the
+ * $coll is empty.
+ */
+ def clear(): Unit
+}
diff --git a/src/library/scala/collection/generic/Growable.scala b/src/library/scala/collection/generic/Growable.scala
index baf332fcd8..d6a263af2f 100644
--- a/src/library/scala/collection/generic/Growable.scala
+++ b/src/library/scala/collection/generic/Growable.scala
@@ -22,7 +22,7 @@ package generic
* @define add add
* @define Add add
*/
-trait Growable[-A] {
+trait Growable[-A] extends Clearable {
/** ${Add}s a single element to this $coll.
*
@@ -50,5 +50,5 @@ trait Growable[-A] {
/** Clears the $coll's contents. After this operation, the
* $coll is empty.
*/
- def clear()
+ def clear(): Unit
}
diff --git a/src/library/scala/reflect/api/RequiredFile.scala b/src/library/scala/reflect/api/RequiredFile.scala
new file mode 100644
index 0000000000..4a54595940
--- /dev/null
+++ b/src/library/scala/reflect/api/RequiredFile.scala
@@ -0,0 +1,7 @@
+package scala.reflect
+package api
+
+trait RequiredFile {
+ def path: String
+ def canonicalPath: String
+}