WASM: Implement string hashcode
This commit is contained in:
committed by
TeamCityServer
parent
c526145a48
commit
af865544ff
@@ -1,5 +1,3 @@
|
|||||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
|
||||||
// WASM_MUTE_REASON: String.hashCode()
|
|
||||||
// IGNORE_BACKEND: NATIVE
|
// IGNORE_BACKEND: NATIVE
|
||||||
|
|
||||||
fun test(s: String) {
|
fun test(s: String) {
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -11728,6 +11728,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt");
|
runTest("compiler/testData/codegen/box/primitiveTypes/rangeTo.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("stringEqualsHashCodeToString.kt")
|
||||||
|
public void testStringEqualsHashCodeToString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/primitiveTypes/stringEqualsHashCodeToString.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unboxComparable.kt")
|
@TestMetadata("unboxComparable.kt")
|
||||||
public void testUnboxComparable() throws Exception {
|
public void testUnboxComparable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt");
|
runTest("compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt");
|
||||||
|
|||||||
@@ -56,8 +56,16 @@ public class String internal constructor(internal val chars: CharArray) : Compar
|
|||||||
|
|
||||||
public override fun toString(): String = this
|
public override fun toString(): String = this
|
||||||
|
|
||||||
// TODO: this is not nice
|
private var cachedHash: Int = 0
|
||||||
public override fun hashCode(): Int = 10
|
public override fun hashCode(): Int {
|
||||||
|
if (cachedHash != 0 || this.isEmpty())
|
||||||
|
return cachedHash
|
||||||
|
var hash = 0
|
||||||
|
for (c in chars)
|
||||||
|
hash = 31 * hash + c.toInt()
|
||||||
|
cachedHash = hash
|
||||||
|
return cachedHash
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun stringLiteral(startAddr: Int, length: Int) = String(unsafeRawMemoryToCharArray(startAddr, length))
|
internal fun stringLiteral(startAddr: Int, length: Int) = String(unsafeRawMemoryToCharArray(startAddr, length))
|
||||||
|
|||||||
Reference in New Issue
Block a user