Introduce runtime ClassValue-based cache for typeOf machinery
* Cache KType instances constructor from the given classifier * For generics, cache KTypes with already substituted arguments * It significantly speeds up all typeOf-based APIs, both accesses to typeOf and its related properties (i.e. classifier) #KT-53508 Merge-request: KT-MR-6818 Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
This commit is contained in:
committed by
Space
parent
c84a70c654
commit
fdd541c1e9
@@ -0,0 +1,24 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertSame
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
private inline fun <reified T> check(isNullable: Boolean = false) {
|
||||
val t1 = typeOf<T>()
|
||||
val t2 = typeOf<T>()
|
||||
assertSame(t1.classifier, t2.classifier)
|
||||
assertEquals(isNullable, t1.isMarkedNullable)
|
||||
assertEquals(isNullable, t2.isMarkedNullable)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check<Int>()
|
||||
check<Int?>(true)
|
||||
check<List<Int>?>(true)
|
||||
check<List<Int>>()
|
||||
check<List<Int?>?>(true)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user