diff options
author | Martin Odersky <odersky@gmail.com> | 2014-02-25 11:13:38 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-02-25 11:13:38 +0100 |
commit | f0ddc9afbef266d3a8f826b2c4e5249dca88242f (patch) | |
tree | 3c2bbe58dca00c12a437af3d2e47ce300d1d8281 /src/dotty/tools/dotc/core/Types.scala | |
parent | a995ab85b7747275a1798cf29ac54466fbe82e2f (diff) | |
download | dotty-f0ddc9afbef266d3a8f826b2c4e5249dca88242f.tar.gz dotty-f0ddc9afbef266d3a8f826b2c4e5249dca88242f.tar.bz2 dotty-f0ddc9afbef266d3a8f826b2c4e5249dca88242f.zip |
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.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 14 |
1 files changed, 13 insertions, 1 deletions
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. |