diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt index 53ad4f7a998..69073237d41 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/approximationKeys.kt @@ -8,16 +8,19 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer import org.jetbrains.kotlin.descriptors.commonizer.utils.intern import org.jetbrains.kotlin.descriptors.commonizer.utils.signature +import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode +import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.name.Name /** Used for approximation of [PropertyDescriptor]s before running concrete [Commonizer]s */ data class PropertyApproximationKey( - val name: Name, - val extensionReceiverParameter: CirTypeSignature? + private val name: Name, + private val extensionReceiverParameterType: CirTypeSignature? ) { constructor(property: PropertyDescriptor) : this( property.name.intern(), @@ -26,23 +29,49 @@ data class PropertyApproximationKey( } /** Used for approximation of [SimpleFunctionDescriptor]s before running concrete [Commonizer]s */ -data class FunctionApproximationKey( - val name: Name, - val valueParameters: List, - val extensionReceiverParameter: CirTypeSignature? +class FunctionApproximationKey( + private val name: Name, + private val valueParametersTypes: Array, + private val extensionReceiverParameterType: CirTypeSignature? ) { constructor(function: SimpleFunctionDescriptor) : this( function.name.intern(), - function.valueParameters.map { it.type.signature }, + function.valueParameters.toTypeSignatures(), function.extensionReceiverParameter?.type?.signature ) + + override fun equals(other: Any?): Boolean { + if (other !is FunctionApproximationKey) + return false + + return name == other.name + && valueParametersTypes.contentEquals(other.valueParametersTypes) + && extensionReceiverParameterType == other.extensionReceiverParameterType + } + + override fun hashCode() = hashCode(name) + .appendHashCode(valueParametersTypes) + .appendHashCode(extensionReceiverParameterType) } /** Used for approximation of [ConstructorDescriptor]s before running concrete [Commonizer]s */ -data class ConstructorApproximationKey( - val valueParameters: List +class ConstructorApproximationKey( + private val valueParametersTypes: Array ) { constructor(constructor: ConstructorDescriptor) : this( - constructor.valueParameters.map { it.type.signature } + constructor.valueParameters.toTypeSignatures() ) -} \ No newline at end of file + + override fun equals(other: Any?): Boolean { + if (other !is ConstructorApproximationKey) + return false + + return valueParametersTypes.contentEquals(other.valueParametersTypes) + } + + override fun hashCode() = hashCode(valueParametersTypes) +} + +@Suppress("NOTHING_TO_INLINE") +private inline fun List.toTypeSignatures(): Array = + Array(size) { index -> this[index].type.signature } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/misc.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/misc.kt index 739a9eba795..bb13a9a2d9a 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/misc.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/utils/misc.kt @@ -31,5 +31,11 @@ internal fun Any?.isNull(): Boolean = this == null @Suppress("NOTHING_TO_INLINE") inline fun hashCode(value: Any?): Int = value.hashCode() +@Suppress("NOTHING_TO_INLINE") +inline fun hashCode(array: Array<*>?): Int = array?.contentHashCode() ?: 0 + @Suppress("NOTHING_TO_INLINE") inline fun Int.appendHashCode(value: Any?): Int = 31 * this + hashCode(value) + +@Suppress("NOTHING_TO_INLINE") +inline fun Int.appendHashCode(array: Array<*>?): Int = 31 * this + hashCode(array)