mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
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
|
||||
|
||||
fun test(s: String) {
|
||||
|
||||
@@ -11728,6 +11728,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
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")
|
||||
public void testUnboxComparable() throws Exception {
|
||||
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
|
||||
|
||||
// TODO: this is not nice
|
||||
public override fun hashCode(): Int = 10
|
||||
private var cachedHash: Int = 0
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user