[K/Wasm] Remove custom equals because this kind of equality is lowered in duration of the compilation ^KT-58126 Fixed

This commit is contained in:
Artem Kobzar
2023-06-20 17:36:01 +00:00
committed by Space Team
parent 4fe3e875fa
commit c53b49d7fa
2 changed files with 2 additions and 49 deletions
@@ -237,8 +237,7 @@ class WasmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(wri
override fun MethodBuilder.modifyGeneratedEquals(thisKind: PrimitiveType) {
val additionalCheck = when (thisKind) {
PrimitiveType.LONG -> "wasm_i64_eq(this, $parameterName)"
PrimitiveType.FLOAT -> "this.equals(other)"
PrimitiveType.DOUBLE -> "this.toBits() == other.toBits()"
PrimitiveType.FLOAT, PrimitiveType.DOUBLE -> "this.toBits() == other.toBits()"
else -> {
"wasm_i32_eq(this${thisKind.castToIfNecessary(PrimitiveType.INT)}, $parameterName${thisKind.castToIfNecessary(PrimitiveType.INT)})"
}
@@ -255,7 +254,6 @@ class WasmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(wri
}
override fun ClassBuilder.generateAdditionalMethods(thisKind: PrimitiveType) {
generateCustomEquals(thisKind)
generateHashCode(thisKind)
when {
thisKind == PrimitiveType.BYTE || thisKind == PrimitiveType.SHORT -> generateReinterpret(PrimitiveType.INT)
@@ -283,25 +281,6 @@ class WasmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(wri
}
}
private fun ClassBuilder.generateCustomEquals(thisKind: PrimitiveType) {
method {
annotations += "kotlin.internal.IntrinsicConstEvaluation"
signature {
isInline = thisKind in PrimitiveType.floatingPoint
methodName = "equals"
parameter {
name = "other"
type = thisKind.capitalized
}
returnType = PrimitiveType.BOOLEAN.capitalized
}
when (thisKind) {
in PrimitiveType.floatingPoint -> "toBits() == other.toBits()".addAsSingleLineBody(bodyOnNewLine = false)
else -> implementAsIntrinsic(thisKind, methodName)
}
}
}
private fun ClassBuilder.generateReinterpret(otherKind: PrimitiveType) {
method {
annotations += "WasmNoOpCast"
@@ -429,11 +429,6 @@ public class Byte private constructor(private val value: Byte) : Number(), Compa
public override fun equals(other: Any?): Boolean =
other is Byte && wasm_i32_eq(this.toInt(), other.toInt())
@kotlin.internal.IntrinsicConstEvaluation
@WasmOp(WasmOp.I32_EQ)
public fun equals(other: Byte): Boolean =
implementedAsIntrinsic
public override fun hashCode(): Int = this.toInt()
@WasmNoOpCast
@@ -858,11 +853,6 @@ public class Short private constructor(private val value: Short) : Number(), Com
public override fun equals(other: Any?): Boolean =
other is Short && wasm_i32_eq(this.toInt(), other.toInt())
@kotlin.internal.IntrinsicConstEvaluation
@WasmOp(WasmOp.I32_EQ)
public fun equals(other: Short): Boolean =
implementedAsIntrinsic
public override fun hashCode(): Int = this.toInt()
@WasmNoOpCast
@@ -1351,11 +1341,6 @@ public class Int private constructor(private val value: Int) : Number(), Compara
public override fun equals(other: Any?): Boolean =
other is Int && wasm_i32_eq(this, other)
@kotlin.internal.IntrinsicConstEvaluation
@WasmOp(WasmOp.I32_EQ)
public fun equals(other: Int): Boolean =
implementedAsIntrinsic
public override fun hashCode(): Int = this
@WasmNoOpCast
@@ -1858,11 +1843,6 @@ public class Long private constructor(private val value: Long) : Number(), Compa
public override fun equals(other: Any?): Boolean =
other is Long && wasm_i64_eq(this, other)
@kotlin.internal.IntrinsicConstEvaluation
@WasmOp(WasmOp.I64_EQ)
public fun equals(other: Long): Boolean =
implementedAsIntrinsic
public override fun hashCode(): Int = ((this ushr 32) xor this).toInt()
}
@@ -2254,10 +2234,7 @@ public class Float private constructor(private val value: Float) : Number(), Com
@kotlin.internal.IntrinsicConstEvaluation
public override fun equals(other: Any?): Boolean =
other is Float && this.equals(other)
@kotlin.internal.IntrinsicConstEvaluation
public inline fun equals(other: Float): Boolean = toBits() == other.toBits()
other is Float && this.toBits() == other.toBits()
public override fun hashCode(): Int = toBits()
}
@@ -2654,8 +2631,5 @@ public class Double private constructor(private val value: Double) : Number(), C
public override fun equals(other: Any?): Boolean =
other is Double && this.toBits() == other.toBits()
@kotlin.internal.IntrinsicConstEvaluation
public inline fun equals(other: Double): Boolean = toBits() == other.toBits()
public override fun hashCode(): Int = toBits().hashCode()
}