diff options
author | Martin Odersky <odersky@gmail.com> | 2012-08-15 19:21:37 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2012-08-20 08:11:05 +0100 |
commit | 51f47a3c3f3dc7e824f96ecbed0d28cf3262d655 (patch) | |
tree | 7d15b03b6e99419f3d1a47caef8418e65fcb5295 /src | |
parent | 0afe071afc8f6743cf1a392666492f7a726b7070 (diff) | |
download | scala-51f47a3c3f3dc7e824f96ecbed0d28cf3262d655.tar.gz scala-51f47a3c3f3dc7e824f96ecbed0d28cf3262d655.tar.bz2 scala-51f47a3c3f3dc7e824f96ecbed0d28cf3262d655.zip |
Optimization to atOwner
Moved costly hashMap updates into SuperAccessors from general tree transformers and replaced by immutable map.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/TypingTransformers.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala | 17 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala index 9e681b321c..82e95523d9 100644 --- a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala +++ b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala @@ -25,19 +25,14 @@ trait TypingTransformers { protected var curTree: Tree = _ protected def typedPos(pos: Position)(tree: Tree) = localTyper typed { atPos(pos)(tree) } - /** a typer for each enclosing class */ - val typers: mutable.Map[Symbol, analyzer.Typer] = new mutable.HashMap - - override def atOwner[A](owner: Symbol)(trans: => A): A = atOwner(curTree, owner)(trans) + override final def atOwner[A](owner: Symbol)(trans: => A): A = atOwner(curTree, owner)(trans) def atOwner[A](tree: Tree, owner: Symbol)(trans: => A): A = { val savedLocalTyper = localTyper // println("transformer atOwner: " + owner + " isPackage? " + owner.isPackage) localTyper = localTyper.atOwner(tree, if (owner.isModule) owner.moduleClass else owner) - typers += Pair(owner, localTyper) val result = super.atOwner(owner)(trans) localTyper = savedLocalTyper - typers -= owner result } diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 2403bb58d0..80777aa701 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -357,9 +357,22 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } } - override def atOwner[A](owner: Symbol)(trans: => A): A = { + /** a typer for each enclosing class */ + private var typers = immutable.Map[Symbol, analyzer.Typer]() + + /** Specialized here for performance; the previous blanked + * introduction of typers in TypingTransformer caused a >5% + * performance hit for the compiler as a whole. + */ + override def atOwner[A](tree: Tree, owner: Symbol)(trans: => A): A = { if (owner.isClass) validCurrentOwner = true - super.atOwner(owner)(trans) + val savedLocalTyper = localTyper + localTyper = localTyper.atOwner(tree, if (owner.isModule) owner.moduleClass else owner) + typers = typers updated (owner, localTyper) + val result = super.atOwner(tree, owner)(trans) + localTyper = savedLocalTyper + typers -= owner + result } private def withInvalidOwner[A](trans: => A): A = { |