Optimize const vals by inlining them at use sites
#KT-11734 Fixed #KT-13570 Fixed
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
|
||||
const val z = 0
|
||||
|
||||
fun a() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
|
||||
const val z = 0
|
||||
|
||||
fun a() {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
const val one = 1
|
||||
const val two = 2
|
||||
|
||||
fun test1() {
|
||||
if (!(one < two)) {
|
||||
val p = 1
|
||||
}
|
||||
}
|
||||
// 0 IF
|
||||
@@ -1,3 +1,5 @@
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
|
||||
const val one = 1
|
||||
const val two = 2
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const val A = 10
|
||||
private const val B = 20
|
||||
|
||||
object Constants {
|
||||
const val C = 30
|
||||
}
|
||||
|
||||
fun foo(state: Int) {
|
||||
when (state) {
|
||||
A -> return
|
||||
B -> return
|
||||
Constants.C -> return
|
||||
else -> return
|
||||
}
|
||||
}
|
||||
|
||||
// 1 LOOKUPSWITCH
|
||||
@@ -0,0 +1,20 @@
|
||||
object Constants {
|
||||
const val A = 30
|
||||
const val B = 40
|
||||
}
|
||||
|
||||
class ClassConstants {
|
||||
companion object {
|
||||
const val C = 50
|
||||
}
|
||||
}
|
||||
fun foo(state: Int) {
|
||||
when (state) {
|
||||
Constants.A -> return
|
||||
Constants.B -> return
|
||||
ClassConstants.C -> return
|
||||
else -> return
|
||||
}
|
||||
}
|
||||
|
||||
// 1 LOOKUPSWITCH
|
||||
@@ -0,0 +1,16 @@
|
||||
const val A = 10
|
||||
private const val B = 20
|
||||
|
||||
object Constants {
|
||||
const val C = 30
|
||||
}
|
||||
|
||||
fun foo(state: Int) {
|
||||
when (state) {
|
||||
A -> return
|
||||
B -> return
|
||||
else -> return
|
||||
}
|
||||
}
|
||||
|
||||
// 1 LOOKUPSWITCH
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
const val y = "cde"
|
||||
|
||||
fun foo(x : String) : String {
|
||||
when (x) {
|
||||
"abc", "${y}" -> return "abc_cde"
|
||||
"e" + "fg", "ghi" -> return "efg_ghi"
|
||||
}
|
||||
|
||||
return "other"
|
||||
}
|
||||
|
||||
// 1 LOOKUPSWITCH
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// LANGUAGE_VERSION: 1.0
|
||||
|
||||
const val y = "cde"
|
||||
|
||||
fun foo(x : String) : String {
|
||||
|
||||
Reference in New Issue
Block a user