[Analysis API] optimize RAM consumption in KtTypes

- remove cache allocation for cases when the value is fast to compute

^KTIJ-22749
This commit is contained in:
Ilya Kirillov
2023-02-03 12:36:22 +01:00
committed by Space Team
parent 2e5d284472
commit e0c23dae47
3 changed files with 8 additions and 7 deletions
@@ -21,7 +21,7 @@ internal class KtFirDefinitelyNotNullType(
override val token: KtLifetimeToken, override val token: KtLifetimeToken,
private val builder: KtSymbolByFirBuilder, private val builder: KtSymbolByFirBuilder,
) : KtDefinitelyNotNullType(), KtFirType { ) : KtDefinitelyNotNullType(), KtFirType {
override val original: KtType by cached { builder.typeBuilder.buildKtType(this.coneType.original) } override val original: KtType = withValidityAssertion { builder.typeBuilder.buildKtType(this.coneType.original) }
override val annotationsList: KtAnnotationsList by cached { override val annotationsList: KtAnnotationsList by cached {
KtFirAnnotationListForType.create(coneType, builder.rootSession, token) KtFirAnnotationListForType.create(coneType, builder.rootSession, token)
} }
@@ -23,8 +23,8 @@ internal class KtFirFlexibleType(
private val builder: KtSymbolByFirBuilder, private val builder: KtSymbolByFirBuilder,
) : KtFlexibleType(), KtFirType { ) : KtFlexibleType(), KtFirType {
override val lowerBound: KtType by cached { builder.typeBuilder.buildKtType(coneType.lowerBound) } override val lowerBound: KtType get() = withValidityAssertion { builder.typeBuilder.buildKtType(coneType.lowerBound) }
override val upperBound: KtType by cached { builder.typeBuilder.buildKtType(coneType.upperBound) } override val upperBound: KtType get() = withValidityAssertion { builder.typeBuilder.buildKtType(coneType.upperBound) }
override val annotationsList: KtAnnotationsList by cached { override val annotationsList: KtAnnotationsList by cached {
KtFirAnnotationListForType.create(coneType, builder.rootSession, token) KtFirAnnotationListForType.create(coneType, builder.rootSession, token)
} }
@@ -27,10 +27,11 @@ internal class KtFirUsualClassType(
private val builder: KtSymbolByFirBuilder, private val builder: KtSymbolByFirBuilder,
) : KtUsualClassType(), KtFirType { ) : KtUsualClassType(), KtFirType {
override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId } override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId }
override val classSymbol: KtClassLikeSymbol by cached { override val classSymbol: KtClassLikeSymbol
builder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag) get() = withValidityAssertion {
?: errorWithFirSpecificEntries("Class was not found", coneType = coneType) builder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag)
} ?: errorWithFirSpecificEntries("Class was not found", coneType = coneType)
}
override val qualifiers by cached { override val qualifiers by cached {
UsualClassTypeQualifierBuilder.buildQualifiers(coneType, builder) UsualClassTypeQualifierBuilder.buildQualifiers(coneType, builder)