Skip to content

Commit cbd6872

Browse files
committed
Optimize typeParams
Direct encoding of lazy val I also tried to mase typeParams tail recursive by addling a local `recur` method. But it turns out the previous typeParams is already fully optimized, no need to add a local function.
1 parent 8e3baa7 commit cbd6872

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,8 +3007,13 @@ object Types {
30073007

30083008
def newParamRef(n: Int) = new TypeParamRef(this, n) {}
30093009

3010-
lazy val typeParams: List[LambdaParam] =
3011-
paramNames.indices.toList.map(new LambdaParam(this, _))
3010+
private[this] var myTypeParams: List[LambdaParam] = null
3011+
3012+
def typeParams: List[LambdaParam] = {
3013+
if (myTypeParams == null)
3014+
myTypeParams = paramNames.indices.toList.map(new LambdaParam(this, _))
3015+
myTypeParams
3016+
}
30123017

30133018
def derivedLambdaAbstraction(paramNames: List[TypeName], paramInfos: List[TypeBounds], resType: Type)(implicit ctx: Context): Type =
30143019
resType match {

0 commit comments

Comments
 (0)