Make stdlib map freezing aware. (#1876)
This commit is contained in:
@@ -707,6 +707,11 @@ task freeze4(type: RunKonanTest) {
|
||||
source = "runtime/workers/freeze4.kt"
|
||||
}
|
||||
|
||||
task freeze5(type: RunKonanTest) {
|
||||
goldValue = "OK\n"
|
||||
source = "runtime/workers/freeze5.kt"
|
||||
}
|
||||
|
||||
task atomic0(type: RunKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // Workers need pthreads.
|
||||
goldValue = "35\n" + "20\n" + "OK\n"
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package runtime.workers.freeze5
|
||||
|
||||
import kotlin.test.*
|
||||
object Keys {
|
||||
internal val myMap: Map<String, List<String>> = mapOf(
|
||||
"val1" to listOf("a1", "a2", "a3"),
|
||||
"val2" to listOf("b1", "b2")
|
||||
)
|
||||
|
||||
fun getKey(name: String): String {
|
||||
for (key in myMap.keys) {
|
||||
if (key == name) {
|
||||
return key
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun getValue(name: String): String {
|
||||
for (value in myMap.values) {
|
||||
if (value.contains(name)) {
|
||||
return name
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun getEntry(name: String): String {
|
||||
for (entry in myMap.entries) {
|
||||
if (entry.key == name) {
|
||||
return entry.key
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@Test fun runTest() {
|
||||
assertEquals("val2", Keys.getKey("val2"))
|
||||
assertEquals("a1", Keys.getValue("a1"))
|
||||
assertEquals("val1", Keys.getEntry("val1"))
|
||||
println("OK")
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
import konan.worker.isFrozen
|
||||
|
||||
actual class HashMap<K, V> private constructor(
|
||||
private var keysArray: Array<K>,
|
||||
private var valuesArray: Array<V>?, // allocated only when actually used, always null in pure HashSet
|
||||
@@ -113,7 +115,8 @@ actual class HashMap<K, V> private constructor(
|
||||
val cur = keysView
|
||||
return if (cur == null) {
|
||||
val new = HashSet(this)
|
||||
keysView = new
|
||||
if (!isFrozen)
|
||||
keysView = new
|
||||
new
|
||||
} else cur
|
||||
}
|
||||
@@ -122,7 +125,8 @@ actual class HashMap<K, V> private constructor(
|
||||
val cur = valuesView
|
||||
return if (cur == null) {
|
||||
val new = HashMapValues(this)
|
||||
valuesView = new
|
||||
if (!isFrozen)
|
||||
valuesView = new
|
||||
new
|
||||
} else cur
|
||||
}
|
||||
@@ -131,7 +135,8 @@ actual class HashMap<K, V> private constructor(
|
||||
val cur = entriesView
|
||||
return if (cur == null) {
|
||||
val new = HashMapEntrySet(this)
|
||||
entriesView = new
|
||||
if (!isFrozen)
|
||||
entriesView = new
|
||||
return new
|
||||
} else cur
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user