[FIR] DeprecationsProvider: caching results

This commit is contained in:
Arseniy Terekhov
2022-08-17 10:58:54 +03:00
committed by teamcity
parent 25fc948d95
commit a80870bc8f
13 changed files with 43 additions and 27 deletions
@@ -7,6 +7,9 @@ package org.jetbrains.kotlin.fir.declarations
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.fir.caches.FirCache
import org.jetbrains.kotlin.fir.caches.FirCachesFactory
import org.jetbrains.kotlin.fir.caches.createCache
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
import org.jetbrains.kotlin.resolve.deprecation.SimpleDeprecationInfo
@@ -17,18 +20,23 @@ abstract class DeprecationsProvider {
}
class DeprecationsProviderImpl(
firCachesFactory: FirCachesFactory,
private val all: List<DeprecationAnnotationInfo>?,
private val bySpecificSite: Map<AnnotationUseSiteTarget, List<DeprecationAnnotationInfo>>?
) : DeprecationsProvider() {
override fun getDeprecationsInfo(version: ApiVersion): DeprecationsPerUseSite {
private val cache: FirCache<ApiVersion, DeprecationsPerUseSite, Nothing?> = firCachesFactory.createCache { version ->
@Suppress("UNCHECKED_CAST")
return DeprecationsPerUseSite(
DeprecationsPerUseSite(
all?.computeDeprecationInfoOrNull(version),
bySpecificSite?.mapValues { (_, info) -> info.computeDeprecationInfoOrNull(version) }?.filterValues { it != null }
as Map<AnnotationUseSiteTarget, DeprecationInfo>?
)
}
override fun getDeprecationsInfo(version: ApiVersion): DeprecationsPerUseSite {
return cache.getValue(version, null)
}
private fun List<DeprecationAnnotationInfo>.computeDeprecationInfoOrNull(version: ApiVersion): DeprecationInfo? {
return firstNotNullOfOrNull { it.computeDeprecationInfo(version) }
}