[FIR] Cleanup caching symbol in ConeClassLikeLookupTagImpl

Type of `boundSymbol` replaced to OneElementWeakMap
`FirSymbolProvider.getSymbolByLookupTag` moved to extensions
This commit is contained in:
Dmitriy Novozhilov
2020-08-13 18:04:26 +03:00
parent 9032234e1d
commit 111b8c0169
10 changed files with 63 additions and 41 deletions
@@ -5,11 +5,16 @@
package org.jetbrains.kotlin.fir.symbols.impl
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.name.ClassId
@RequiresOptIn
annotation class LookupTagInternals
class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag() {
var boundSymbol: Pair<*, FirClassLikeSymbol<*>?>? = null
@LookupTagInternals
var boundSymbol: OneElementWeakMap<FirSession, FirClassLikeSymbol<*>?>? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
@@ -25,4 +30,4 @@ class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeL
override fun hashCode(): Int {
return classId.hashCode()
}
}
}
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2020 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.symbols.impl
import java.lang.ref.WeakReference
class OneElementWeakMap<K, V> private constructor(
private val keyReference: WeakReference<K>,
private val valueReference: WeakReference<V>
) {
constructor(key: K, value: V) : this(WeakReference(key), WeakReference(value))
val key: K?
get() = keyReference.get()
val value: V?
get() = valueReference.get()
}