Provide optimized code generation for for-in-withIndex for arrays

#KT-5177 In Progress
This commit is contained in:
Dmitry Petrov
2018-01-19 15:25:32 +03:00
parent e07e9c0ea5
commit 08622b0953
23 changed files with 664 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
// WITH_RUNTIME
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
val s = StringBuilder()
for ((i, _) in arr.withIndex()) {
s.append("$i;")
}
val ss = s.toString()
return if (ss == "0;1;2;3;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 0 iterator
// 0 hasNext
// 0 next
// 0 component1
// 0 component2
// 1 ARRAYLENGTH

View File

@@ -0,0 +1,22 @@
// WITH_RUNTIME
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
val s = StringBuilder()
for ((_, x) in arr.withIndex()) {
s.append("$x;")
}
val ss = s.toString()
return if (ss == "a;b;c;d;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 0 iterator
// 0 hasNext
// 0 next
// 0 component1
// 0 component2
// 1 ARRAYLENGTH

View File

@@ -0,0 +1,19 @@
// WITH_RUNTIME
val arr = intArrayOf()
fun box(): String {
val s = StringBuilder()
for ((index, x) in arr.withIndex()) {
return "Loop over empty array should not be executed"
}
return "OK"
}
// 0 withIndex
// 0 iterator
// 0 hasNext
// 0 next
// 0 component1
// 0 component2
// 1 ARRAYLENGTH

View File

@@ -0,0 +1,20 @@
// WITH_RUNTIME
val arr = intArrayOf(10, 20, 30, 40)
fun box(): String {
val s = StringBuilder()
for ((index, x) in arr.withIndex()) {
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:10;1:20;2:30;3:40;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 0 iterator
// 0 hasNext
// 0 next
// 0 component1
// 0 component2
// 1 ARRAYLENGTH

View File

@@ -0,0 +1,22 @@
// WITH_RUNTIME
val arr = arrayOf("a", "b", "c", "d")
fun box(): String {
val s = StringBuilder()
for ((index, x) in arr.withIndex()) {
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 0 iterator
// 0 hasNext
// 0 next
// 0 component1
// 0 component2
// 1 ARRAYLENGTH