diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-01-10 14:54:03 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-01-10 14:54:03 +0000 |
commit | 158e748e44932beb477d5bc69a062a6f738efd91 (patch) | |
tree | b621672d8314f0bff4da6c393f1ffb5256e93686 /src/compiler | |
parent | 0b78a0196af2525c4ba6978f2eb79d8abc6ec7e1 (diff) | |
download | scala-158e748e44932beb477d5bc69a062a6f738efd91.tar.gz scala-158e748e44932beb477d5bc69a062a6f738efd91.tar.bz2 scala-158e748e44932beb477d5bc69a062a6f738efd91.zip |
Second try for "Changing the intersectionWitnes...
Second try for "Changing the intersectionWitness map to use weak
references for the value. A value may prevent parts of this map from
collecting, since the value may hold a (strong) reference to one of the
keys in the map. review by odersky." This time without higher order
functions.
This updates commit 71bce88e543277bd9afeb23e3e6af2b517b56075.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 23 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 1 |
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 { |