[WASM] Replace deprecated Char.toInt() with Char.code

This commit is contained in:
Ivan Kylchik
2023-07-24 11:33:05 +02:00
committed by Space Team
parent ee973c0ede
commit adce2c9a78
4 changed files with 24 additions and 24 deletions
@@ -490,32 +490,32 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
} }
override fun MethodBuilder.modifyGeneratedCompareTo() { override fun MethodBuilder.modifyGeneratedCompareTo() {
"wasm_i32_compareTo(this.toInt(), other.toInt())".addAsSingleLineBody(bodyOnNewLine = true) "wasm_i32_compareTo(this.code, other.code)".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedPlus() { override fun MethodBuilder.modifyGeneratedPlus() {
modifySignature { isInline = true } modifySignature { isInline = true }
"(this.toInt() + other).toChar()".addAsSingleLineBody(bodyOnNewLine = true) "(this.code + other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedMinusChar() { override fun MethodBuilder.modifyGeneratedMinusChar() {
modifySignature { isInline = true } modifySignature { isInline = true }
"(this.toInt() - other.toInt())".addAsSingleLineBody(bodyOnNewLine = true) "(this.code - other.code)".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedMinusInt() { override fun MethodBuilder.modifyGeneratedMinusInt() {
modifySignature { isInline = true } modifySignature { isInline = true }
"(this.toInt() - other).toChar()".addAsSingleLineBody(bodyOnNewLine = true) "(this.code - other).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedInc() { override fun MethodBuilder.modifyGeneratedInc() {
modifySignature { isInline = true } modifySignature { isInline = true }
"(this.toInt() + 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true) "(this.code + 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedDec() { override fun MethodBuilder.modifyGeneratedDec() {
modifySignature { isInline = true } modifySignature { isInline = true }
"(this.toInt() - 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true) "(this.code - 1).toChar()".addAsSingleLineBody(bodyOnNewLine = true)
} }
override fun MethodBuilder.modifyGeneratedRangeTo() { override fun MethodBuilder.modifyGeneratedRangeTo() {
@@ -534,7 +534,7 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
annotations += "WasmNoOpCast" annotations += "WasmNoOpCast"
"implementedAsIntrinsic" "implementedAsIntrinsic"
} }
else -> "this.toInt().$methodName()" else -> "this.code.$methodName()"
} }
body.addAsSingleLineBody(bodyOnNewLine = true) body.addAsSingleLineBody(bodyOnNewLine = true)
} }
@@ -542,7 +542,7 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
override fun MethodBuilder.modifyGeneratedEquals() { override fun MethodBuilder.modifyGeneratedEquals() {
""" """
if (other is Char) if (other is Char)
return wasm_i32_eq(this.toInt(), other.toInt()) return wasm_i32_eq(this.code, other.code)
return false return false
""".trimIndent().addAsMultiLineBody() """.trimIndent().addAsMultiLineBody()
} }
@@ -558,7 +558,7 @@ class WasmCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
override fun MethodBuilder.modifyGeneratedHashCode() { override fun MethodBuilder.modifyGeneratedHashCode() {
modifySignature { visibility = null } modifySignature { visibility = null }
"this.toInt().hashCode()".addAsSingleLineBody(bodyOnNewLine = true) "this.code.hashCode()".addAsSingleLineBody(bodyOnNewLine = true)
} }
} }
+13 -13
View File
@@ -21,22 +21,22 @@ public class Char private constructor(private val value: Char) : Comparable<Char
*/ */
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public override fun compareTo(other: Char): Int = public override fun compareTo(other: Char): Int =
wasm_i32_compareTo(this.toInt(), other.toInt()) wasm_i32_compareTo(this.code, other.code)
/** Adds the other Int value to this value resulting a Char. */ /** Adds the other Int value to this value resulting a Char. */
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Int): Char = public inline operator fun plus(other: Int): Char =
(this.toInt() + other).toChar() (this.code + other).toChar()
/** Subtracts the other Char value from this value resulting an Int. */ /** Subtracts the other Char value from this value resulting an Int. */
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Char): Int = public inline operator fun minus(other: Char): Int =
(this.toInt() - other.toInt()) (this.code - other.code)
/** Subtracts the other Int value from this value resulting a Char. */ /** Subtracts the other Int value from this value resulting a Char. */
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Int): Char = public inline operator fun minus(other: Int): Char =
(this.toInt() - other).toChar() (this.code - other).toChar()
/** /**
* Returns this value incremented by one. * Returns this value incremented by one.
@@ -44,7 +44,7 @@ public class Char private constructor(private val value: Char) : Comparable<Char
* @sample samples.misc.Builtins.inc * @sample samples.misc.Builtins.inc
*/ */
public inline operator fun inc(): Char = public inline operator fun inc(): Char =
(this.toInt() + 1).toChar() (this.code + 1).toChar()
/** /**
* Returns this value decremented by one. * Returns this value decremented by one.
@@ -52,7 +52,7 @@ public class Char private constructor(private val value: Char) : Comparable<Char
* @sample samples.misc.Builtins.dec * @sample samples.misc.Builtins.dec
*/ */
public inline operator fun dec(): Char = public inline operator fun dec(): Char =
(this.toInt() - 1).toChar() (this.code - 1).toChar()
/** Creates a range from this value to the specified [other] value. */ /** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Char): CharRange = public operator fun rangeTo(other: Char): CharRange =
@@ -73,7 +73,7 @@ public class Char private constructor(private val value: Char) : Comparable<Char
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline fun toByte(): Byte = public inline fun toByte(): Byte =
this.toInt().toByte() this.code.toByte()
/** Returns the value of this character as a `Char`. */ /** Returns the value of this character as a `Char`. */
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
@@ -85,7 +85,7 @@ public class Char private constructor(private val value: Char) : Comparable<Char
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline fun toShort(): Short = public inline fun toShort(): Short =
this.toInt().toShort() this.code.toShort()
/** Returns the value of this character as a `Int`. */ /** Returns the value of this character as a `Int`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code")) @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code"))
@@ -100,21 +100,21 @@ public class Char private constructor(private val value: Char) : Comparable<Char
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline fun toLong(): Long = public inline fun toLong(): Long =
this.toInt().toLong() this.code.toLong()
/** Returns the value of this character as a `Float`. */ /** Returns the value of this character as a `Float`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()")) @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()"))
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline fun toFloat(): Float = public inline fun toFloat(): Float =
this.toInt().toFloat() this.code.toFloat()
/** Returns the value of this character as a `Double`. */ /** Returns the value of this character as a `Double`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()")) @Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()"))
@DeprecatedSinceKotlin(warningSince = "1.5") @DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public inline fun toDouble(): Double = public inline fun toDouble(): Double =
this.toInt().toDouble() this.code.toDouble()
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
override fun toString(): String { override fun toString(): String {
@@ -126,12 +126,12 @@ public class Char private constructor(private val value: Char) : Comparable<Char
@kotlin.internal.IntrinsicConstEvaluation @kotlin.internal.IntrinsicConstEvaluation
public override fun equals(other: Any?): Boolean { public override fun equals(other: Any?): Boolean {
if (other is Char) if (other is Char)
return wasm_i32_eq(this.toInt(), other.toInt()) return wasm_i32_eq(this.code, other.code)
return false return false
} }
override fun hashCode(): Int = override fun hashCode(): Int =
this.toInt().hashCode() this.code.hashCode()
public companion object { public companion object {
/** /**
@@ -126,7 +126,7 @@ public class String internal @WasmPrimitiveConstructor constructor(
val thisChars = chars val thisChars = chars
var hash = 0 var hash = 0
repeat(thisLength) { repeat(thisLength) {
hash = (hash shl 5) - hash + thisChars.get(it).toInt() hash = (hash shl 5) - hash + thisChars.get(it).code
} }
_hashCode = hash _hashCode = hash
return _hashCode return _hashCode
@@ -351,7 +351,7 @@ internal fun kotlinShortToExternRefAdapter(x: Short): ExternalInterfaceType =
intToExternref(x.toInt()) intToExternref(x.toInt())
internal fun kotlinCharToExternRefAdapter(x: Char): ExternalInterfaceType = internal fun kotlinCharToExternRefAdapter(x: Char): ExternalInterfaceType =
intToExternref(x.toInt()) intToExternref(x.code)
internal fun newJsArray(): ExternalInterfaceType = internal fun newJsArray(): ExternalInterfaceType =
js("[]") js("[]")