summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala23
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala1
2 files changed, 19 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index e3fb82385b..03f4b088a5 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -7,8 +7,8 @@ package scala.tools.nsc
package symtab
import scala.collection.{ mutable, immutable }
-import scala.collection.mutable.ListBuffer
import scala.ref.WeakReference
+import scala.collection.mutable.ListBuffer
import ast.TreeGen
import util.{ Position, NoPosition }
import util.Statistics._
@@ -1342,12 +1342,27 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
baseClassesCache
}
- def memo[A](op1: => A)(op2: Type => A) = {
- (for (ref <- intersectionWitness.get(parents); w <- ref.get)
- yield if (w eq this) op1 else op2(w)) getOrElse {
+ /** The slightly less idiomatic use of Options is due to
+ * performance considerations. A version using for comprehensions
+ * might be too slow (this is deemed a hotspot of the type checker).
+ *
+ * See with Martin before changing this method.
+ */
+ def memo[A](op1: => A)(op2: Type => A): A = {
+ def updateCache(): A = {
intersectionWitness(parents) = new WeakReference(this)
op1
}
+
+ intersectionWitness get parents match {
+ case Some(ref) =>
+ ref.get match {
+ case Some(w) => if (w eq this) op1 else op2(w)
+ case None => updateCache()
+ }
+ case None => updateCache()
+ }
+
}
override def baseType(sym: Symbol): Type = {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 522e39837a..7788ff489c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -49,7 +49,6 @@ trait Typers extends Modes {
resetNamer()
resetImplicits()
transformed.clear()
- //println("%,d entries in intersectionWitness".format(intersectionWitness.size))
}
object UnTyper extends Traverser {