diff options
author | Paul Phillips <paulp@improving.org> | 2010-12-28 21:33:18 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-12-28 21:33:18 +0000 |
commit | 969fd08a04cac5951d35e36ca639433355b5cf80 (patch) | |
tree | 271e77ae4df3fd18ba8d6278fffac5c1baaf4c0b | |
parent | d04cfc06f0ebc671f95e881131d961631de638a2 (diff) | |
download | scala-969fd08a04cac5951d35e36ca639433355b5cf80.tar.gz scala-969fd08a04cac5951d35e36ca639433355b5cf80.tar.bz2 scala-969fd08a04cac5951d35e36ca639433355b5cf80.zip |
After profiling revealed 100Ks of unnecessary s...
After profiling revealed 100Ks of unnecessary singleTypes being created,
I tracked it down to typeOfThis on ClassSymbol. I put in a cache like
the one on thisType and knocked almost 5% off the quick.comp time.
Review by odersky.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 3e03c92460..99a6b1521e 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1990,6 +1990,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => private var thisTypeCache: Type = _ private var thisTypePeriod = NoPeriod + private var typeOfThisCache: Type = _ + private var typeOfThisPeriod = NoPeriod + /** the type this.type in this class */ override def thisType: Type = { val period = thisTypePeriod @@ -2005,10 +2008,18 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => /** the self type of an object foo is foo.type, not class<foo>.this.type */ - override def typeOfThis: Type = - if (getFlag(MODULE | IMPLCLASS) == MODULE.toLong && owner != NoSymbol) - singleType(owner.thisType, sourceModule) + override def typeOfThis: Type = { + if (getFlag(MODULE | IMPLCLASS) == MODULE.toLong && owner != NoSymbol) { + val period = typeOfThisPeriod + if (period != currentPeriod) { + typeOfThisPeriod = currentPeriod + if (!isValid(period)) + typeOfThisCache = singleType(owner.thisType, sourceModule) + } + typeOfThisCache + } else thissym.tpe + } /** Sets the self type of the class */ override def typeOfThis_=(tp: Type) { |