From e54640ddadbbde74ea49aaf4c624e5fd176e6fd0 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Tue, 18 Feb 2020 13:06:00 +0700 Subject: [PATCH] [Commonizer] Apply interner to avoid duplicated CirGetter objects --- .../commonizer/mergedtree/ir/CirProperty.kt | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt index 426b870ebf4..4d46ab90543 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirProperty.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirGetter.Companion.toGetter import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSetter.Companion.toSetter +import org.jetbrains.kotlin.descriptors.commonizer.utils.NonThreadSafeInterner import org.jetbrains.kotlin.resolve.constants.ConstantValue interface CirProperty : CirFunctionOrProperty { @@ -69,20 +70,37 @@ interface CirPropertyAccessor { val isInline: Boolean } -data class CirGetter( +@Suppress("DataClassPrivateConstructor") +data class CirGetter private constructor( override val annotations: List, override val isDefault: Boolean, override val isExternal: Boolean, override val isInline: Boolean ) : CirPropertyAccessor { companion object { - val DEFAULT_NO_ANNOTATIONS = CirGetter(emptyList(), isDefault = true, isExternal = false, isInline = false) + private val interner = NonThreadSafeInterner() + + val DEFAULT_NO_ANNOTATIONS = interner.intern( + CirGetter( + annotations = emptyList(), + isDefault = true, + isExternal = false, + isInline = false + ) + ) fun PropertyGetterDescriptor.toGetter() = if (isDefault && annotations.isEmpty()) DEFAULT_NO_ANNOTATIONS else - CirGetter(annotations.map(CirAnnotation.Companion::create), isDefault, isExternal, isInline) + interner.intern( + CirGetter( + annotations = annotations.map(CirAnnotation.Companion::create), + isDefault = isDefault, + isExternal = isExternal, + isInline = isInline + ) + ) } }