aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-02-26 10:01:57 +0100
committerMartin Odersky <odersky@gmail.com>2014-02-26 11:03:20 +0100
commit311136b60d2de17f46b643d84a949b8f77411c0f (patch)
tree22aa6be9a313c22c7f60ac880a3da4a4f6f3157c /src
parent6029c748f1dc086d058d6b5fd3d37c04c08318b3 (diff)
downloaddotty-311136b60d2de17f46b643d84a949b8f77411c0f.tar.gz
dotty-311136b60d2de17f46b643d84a949b8f77411c0f.tar.bz2
dotty-311136b60d2de17f46b643d84a949b8f77411c0f.zip
Performance improvements: Split long TypeMap#mapOver and move hot fields into locals.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala1
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala37
-rw-r--r--src/dotty/tools/dotc/core/Types.scala128
3 files changed, 92 insertions, 74 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 823c23841..137bbed34 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -575,6 +575,7 @@ object Denotations {
type AsSeenFromResult = SingleDenotation
protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {
+ val symbol = this.symbol
val owner = this match {
case thisd: SymDenotation => thisd.owner
case _ => if (symbol.exists) symbol.owner else NoSymbol
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index e5ec37393..7054ce37f 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -280,24 +280,27 @@ class TypeComparer(initctx: Context) extends DotClass {
def firstTry(tp1: Type, tp2: Type): Boolean = {
tp2 match {
case tp2: NamedType =>
- def compareNamed = tp1 match {
- case tp1: NamedType =>
- val sym1 = tp1.symbol
- ( if (sym1 eq tp2.symbol) (
- ctx.erasedTypes
+ def compareNamed = {
+ implicit val ctx = this.ctx
+ tp1 match {
+ case tp1: NamedType =>
+ val sym1 = tp1.symbol
+ (if (sym1 eq tp2.symbol) (
+ ctx.erasedTypes
|| sym1.isStaticOwner
- || { val pre1 = tp1.prefix
- val pre2 = tp2.prefix
- isSubType(pre1, pre2) ||
- pre1.isInstanceOf[ThisType] && pre2.isInstanceOf[ThisType]
- }
- ) else
- (tp1.name eq tp2.name) && isSubType(tp1.prefix, tp2.prefix)
- ) || secondTryNamed(tp1, tp2)
- case ThisType(cls) if cls eq tp2.symbol.moduleClass =>
- isSubType(cls.owner.thisType, tp2.prefix)
- case _ =>
- secondTry(tp1, tp2)
+ || {
+ val pre1 = tp1.prefix
+ val pre2 = tp2.prefix
+ isSubType(pre1, pre2) ||
+ pre1.isInstanceOf[ThisType] && pre2.isInstanceOf[ThisType]
+ })
+ else
+ (tp1.name eq tp2.name) && isSubType(tp1.prefix, tp2.prefix)) || secondTryNamed(tp1, tp2)
+ case ThisType(cls) if cls eq tp2.symbol.moduleClass =>
+ isSubType(cls.owner.thisType, tp2.prefix)
+ case _ =>
+ secondTry(tp1, tp2)
+ }
}
compareNamed
case tp2: ProtoType =>
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 299b9ba1e..6973af726 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -2099,73 +2099,87 @@ object Types {
protected var variance = 1
/** Map this function over given type */
- def mapOver(tp: Type): Type = tp match {
- case tp: NamedType =>
- if (stopAtStatic && tp.symbol.isStatic) tp
- else tp.derivedSelect(this(tp.prefix))
-
- case _: ThisType
- | _: BoundType
- | NoPrefix => tp
-
- case tp: RefinedType =>
- tp.derivedRefinedType(this(tp.parent), tp.refinedName, this(tp.refinedInfo))
-
- case tp @ TypeBounds(lo, hi) =>
- if (lo eq hi) {
- val saved = variance
- variance = variance * tp.variance
- val lo1 = this(lo)
- variance = saved
- tp.derivedTypeAlias(lo1)
- } else {
- variance = -variance
- val lo1 = this(lo)
- variance = -variance
- tp.derivedTypeBounds(lo1, this(hi))
- }
-
- case tp @ MethodType(pnames, ptypes) =>
- variance = -variance
- val ptypes1 = ptypes mapConserve this
- variance = -variance
- tp.derivedMethodType(pnames, ptypes1, this(tp.resultType))
+ def mapOver(tp: Type): Type = {
+ implicit val ctx = this.ctx
+ tp match {
+ case tp: NamedType =>
+ if (stopAtStatic && tp.symbol.isStatic) tp
+ else tp.derivedSelect(this(tp.prefix))
- case tp @ ExprType(restpe) =>
- tp.derivedExprType(this(restpe))
+ case _: ThisType
+ | _: BoundType
+ | NoPrefix => tp
- case tp @ PolyType(pnames) =>
- variance = -variance
- val bounds1 = tp.paramBounds.mapConserve(apply(_).bounds)
- variance = -variance
- tp.derivedPolyType(
- pnames, bounds1, this(tp.resultType))
+ case tp: RefinedType =>
+ tp.derivedRefinedType(this(tp.parent), tp.refinedName, this(tp.refinedInfo))
+
+ case tp: TypeBounds =>
+ def mapOverBounds = {
+ val lo = tp.lo
+ val hi = tp.hi
+ if (lo eq hi) {
+ val saved = variance
+ variance = variance * tp.variance
+ val lo1 = this(lo)
+ variance = saved
+ tp.derivedTypeAlias(lo1)
+ } else {
+ variance = -variance
+ val lo1 = this(lo)
+ variance = -variance
+ tp.derivedTypeBounds(lo1, this(hi))
+ }
+ }
+ mapOverBounds
+
+ case tp: MethodType =>
+ def mapOverMethod = {
+ variance = -variance
+ val ptypes1 = tp.paramTypes mapConserve this
+ variance = -variance
+ tp.derivedMethodType(tp.paramNames, ptypes1, this(tp.resultType))
+ }
+ mapOverMethod
+
+ case tp: ExprType =>
+ tp.derivedExprType(this(tp.resultType))
+
+ case tp: PolyType =>
+ def mapOverPoly = {
+ variance = -variance
+ val bounds1 = tp.paramBounds.mapConserve(this).asInstanceOf[List[TypeBounds]]
+ variance = -variance
+ tp.derivedPolyType(
+ tp.paramNames, bounds1, this(tp.resultType))
+ }
+ mapOverPoly
- case tp @ SuperType(thistp, supertp) =>
- tp.derivedSuperType(this(thistp), this(supertp))
+ case tp @ SuperType(thistp, supertp) =>
+ tp.derivedSuperType(this(thistp), this(supertp))
- case tp: ClassInfo =>
- mapClassInfo(tp)
+ case tp: ClassInfo =>
+ mapClassInfo(tp)
- case tp: TypeVar =>
- val inst = tp.instanceOpt
- if (inst.exists) apply(inst) else tp
+ case tp: TypeVar =>
+ val inst = tp.instanceOpt
+ if (inst.exists) apply(inst) else tp
- case tp: AndOrType =>
- tp.derivedAndOrType(this(tp.tp1), this(tp.tp2))
+ case tp: AndOrType =>
+ tp.derivedAndOrType(this(tp.tp1), this(tp.tp2))
- case tp @ AnnotatedType(annot, underlying) =>
- val underlying1 = mapOver(underlying)
- if (underlying1 eq underlying) tp else underlying1
+ case tp @ AnnotatedType(annot, underlying) =>
+ val underlying1 = this(underlying)
+ if (underlying1 eq underlying) tp else underlying1
- case tp @ WildcardType =>
- tp.derivedWildcardType(mapOver(tp.optBounds))
+ case tp @ WildcardType =>
+ tp.derivedWildcardType(mapOver(tp.optBounds))
- case tp: ProtoType =>
- tp.map(this)
+ case tp: ProtoType =>
+ tp.map(this)
- case _ =>
- tp
+ case _ =>
+ tp
+ }
}
def mapOver(syms: List[Symbol]): List[Symbol] =