[FIR] Store cachedExpandedType in WeakPair instead of usual Pair

WeakPair is a renamed OneElementWeakMap
This commit is contained in:
Dmitriy Novozhilov
2021-04-13 18:10:12 +03:00
parent dd96c3b56e
commit 7c6a9aa963
6 changed files with 41 additions and 29 deletions
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.types.ConeAttributes
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.ConeNullability
import org.jetbrains.kotlin.fir.utils.WeakPair
class ConeClassLikeTypeImpl(
override val lookupTag: ConeClassLikeLookupTag,
@@ -20,7 +21,7 @@ class ConeClassLikeTypeImpl(
override val nullability: ConeNullability = ConeNullability.create(isNullable)
// Cached expanded type and the relevant session
var cachedExpandedType: Pair<*, ConeClassLikeType>? = null
var cachedExpandedType: WeakPair<*, ConeClassLikeType>? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.utils
import java.lang.ref.WeakReference
class WeakPair<K, V>(first: K, second: V) {
private val firstReference: WeakReference<K> = WeakReference(first)
private val secondReference: WeakReference<V> = WeakReference(second)
val first: K?
get() = firstReference.get()
val second: V?
get() = secondReference.get()
}
operator fun <K, V> WeakPair<K, V>?.component1(): K? {
return this?.first
}
operator fun <K, V> WeakPair<K, V>?.component2(): V? {
return this?.second
}