From f0ddc9afbef266d3a8f826b2c4e5249dca88242f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 25 Feb 2014 11:13:38 +0100 Subject: Performance improvement: Avoid most operations in interpolateUndetVars Perform the operation only if there are qualifying type variables, which is rarely the case. Reverted variances optimization to simpler and shorter previous implementation, because variances is no longer hot. --- src/dotty/tools/dotc/core/Types.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/core/Types.scala') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 00d719acb..5c65b7ede 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -838,7 +838,19 @@ object Types { * 0 means: mixed or non-variant occurrences */ def variances(include: TypeVar => Boolean)(implicit ctx: Context): VarianceMap = track("variances") { - ctx.addVariances(SimpleMap.Empty, this, +1, include, null) + val accu = new TypeAccumulator[VarianceMap] { + def apply(vmap: VarianceMap, t: Type): VarianceMap = t match { + case t: TypeVar + if !t.isInstantiated && (ctx.typerState.constraint contains t) && include(t) => + val v = vmap(t) + if (v == null) vmap.updated(t, variance) + else if (v == variance) vmap + else vmap.updated(t, 0) + case _ => + foldOver(vmap, t) + } + } + accu(SimpleMap.Empty, this) } /** A simplified version of this type which is equivalent wrt =:= to this type. -- cgit v1.2.3