Avoid resolving array-set method several times

While origin problem was in NI, it's also nice to have this change in OI
 in order to slightly improve performance

 #KT-33125 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-09-03 19:38:23 +03:00
parent f8449bf15a
commit e21da3a61a
8 changed files with 87 additions and 11 deletions
@@ -0,0 +1,40 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS_IR
import kotlin.experimental.ExperimentalTypeInference
interface Foo<T>
class FooImpl<T> : Foo<T>
@UseExperimental(ExperimentalTypeInference::class)
fun <T> myflow(@BuilderInference block: Foo<T>.() -> Unit): Foo<T> {
val impl = FooImpl<T>()
impl.block()
return impl
}
class MapWithPlusOperator<K, V>(val m: MutableMap<K, V>)
operator fun <K, V> MapWithPlusOperator<in K, in V>.plus(pair: Pair<K, V>): MapWithPlusOperator<K, V> {
m[pair.first] = pair.second
return this as MapWithPlusOperator<K, V>
}
var publicOk = "noOk"
fun test(map: MutableMap<Int, Any>): Foo<Any> {
var other: MapWithPlusOperator<Int, Any> = MapWithPlusOperator(mutableMapOf())
return myflow {
publicOk = "OK"
map += 1 to "s"
other += 1 to ("s" as Any)
map[0] = Any()
}
}
fun box(): String {
test(mutableMapOf(1 to ""))
return publicOk
}