diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2010-12-16 15:24:34 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2010-12-16 15:24:34 +0000 |
commit | 9ada1110c5311f5a383a8ba48be59aae9337cead (patch) | |
tree | 551146091678ce3057b3b91068c668893a478772 /src/compiler | |
parent | 5c6c2c243c3ba8d4e54af448ef96ed0d8ced3e42 (diff) | |
download | scala-9ada1110c5311f5a383a8ba48be59aae9337cead.tar.gz scala-9ada1110c5311f5a383a8ba48be59aae9337cead.tar.bz2 scala-9ada1110c5311f5a383a8ba48be59aae9337cead.zip |
Make the ownPhaseCache field a weak reference.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/SubComponent.scala | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/SubComponent.scala b/src/compiler/scala/tools/nsc/SubComponent.scala index 445021f22a..4fa9411357 100644 --- a/src/compiler/scala/tools/nsc/SubComponent.scala +++ b/src/compiler/scala/tools/nsc/SubComponent.scala @@ -5,6 +5,8 @@ package scala.tools.nsc +import scala.ref.WeakReference + /** An nsc sub-component. * * @author Martin Odersky @@ -42,16 +44,20 @@ abstract class SubComponent { /** The phase factory */ def newPhase(prev: Phase): Phase - private var ownPhaseCache: Phase = _ + private var ownPhaseCache: WeakReference[Phase] = new WeakReference(null) private var ownPhaseRunId = global.NoRunId /** The phase corresponding to this subcomponent in the current compiler run */ def ownPhase: Phase = { - if (ownPhaseRunId != global.currentRunId) { - ownPhaseCache = global.currentRun.phaseNamed(phaseName) - ownPhaseRunId = global.currentRunId + ownPhaseCache.get match { + case Some(phase) if ownPhaseRunId == global.currentRunId => + phase + case _ => + val phase = global.currentRun.phaseNamed(phaseName) + ownPhaseCache = new WeakReference(phase) + ownPhaseRunId = global.currentRunId + phase } - ownPhaseCache } /** The phase defined by this subcomponent. Can be called only after phase is installed by newPhase. */ |