aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
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/dotty/tools/dotc/core/Types.scala
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/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala128
1 files changed, 71 insertions, 57 deletions
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] =