KT-14258 Optimize accesses to properties defined into companion

- Use direct access to property defined into companion object when
it is possible rather than always use an accessor to access the
property.
- Use direct access will speedup runtime performance.
- Avoid to generate useless accessors for companion properties.

Fix of https://youtrack.jetbrains.com/issue/KT-14258
This commit is contained in:
Mikaël Peltier
2018-02-14 11:33:57 +01:00
committed by Alexander Udalov
parent fd244be9ca
commit d0ed0c4049
17 changed files with 220 additions and 53 deletions
@@ -0,0 +1,20 @@
// Checks that methods 'access$getMy$p' and 'getMy' are not generated and
// that backed field 'my' is accessed through 'access$getMy$cp'
class My {
companion object {
private val my: String = "OK"
fun test(): String {
// accessor is required because field is move to Foo
return my
}
}
fun getMyValue() = test()
}
// 1 GETSTATIC My.my
// 0 INVOKESTATIC My\$Companion.access\$getMy\$p
// 1 INVOKESTATIC My.access\$getMy\$cp
// 0 INVOKESPECIAL My\$Companion.getMy