JVM_IR: Specialize iterator if possible
fixes KT-47171
This commit is contained in:
committed by
Alexander Udalov
parent
8bcdc70adc
commit
1b776bd5b6
@@ -0,0 +1,28 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// CHECK_BYTECODE_LISTING
|
||||
|
||||
fun myFun(iterator: MyUIntIterator) {
|
||||
for (x in iterator) {
|
||||
assert(x == 42u)
|
||||
}
|
||||
}
|
||||
|
||||
class MyUIntIterator : Iterator<UInt> {
|
||||
private var count = 1
|
||||
override fun hasNext(): Boolean = count-- > 0
|
||||
override fun next(): UInt = 42u
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
myFun(MyUIntIterator())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// CHECK_BYTECODE_TEXT
|
||||
// JVM_IR_TEMPLATES
|
||||
// 0 java/util/Iterator.hasNext \(\)Z
|
||||
// 0 java/util/Iterator.next \(\)Ljava/lang/Object;
|
||||
// 1 MyUIntIterator.hasNext \(\)Z
|
||||
// 1 public synthetic bridge next\(\)Ljava/lang/Object;
|
||||
// 2 MyUIntIterator.next-pVg5ArA \(\)I
|
||||
@@ -0,0 +1,17 @@
|
||||
@kotlin.Metadata
|
||||
public final class ForInIteratorKt {
|
||||
// source: 'forInIterator.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method myFun(@org.jetbrains.annotations.NotNull p0: MyUIntIterator): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class MyUIntIterator {
|
||||
// source: 'forInIterator.kt'
|
||||
private field count: int
|
||||
public method <init>(): void
|
||||
public method hasNext(): boolean
|
||||
public synthetic bridge method next(): java.lang.Object
|
||||
public method next-pVg5ArA(): int
|
||||
public method remove(): void
|
||||
}
|
||||
Reference in New Issue
Block a user