mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 00:21:47 +00:00
Provide optimized code generation for for-in-withIndex for arrays
#KT-5177 In Progress
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
19
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInEmptyArrrayWithIndex.kt
vendored
Normal file
19
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInEmptyArrrayWithIndex.kt
vendored
Normal 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
|
||||
20
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInIntArrrayWithIndex.kt
vendored
Normal file
20
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInIntArrrayWithIndex.kt
vendored
Normal 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
|
||||
22
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInObjectArrrayWithIndex.kt
vendored
Normal file
22
compiler/testData/codegen/bytecodeText/forLoop/forInArrayWithIndex/forInObjectArrrayWithIndex.kt
vendored
Normal 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
|
||||
Reference in New Issue
Block a user