diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForInOptimizedIndicesLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForInOptimizedIndicesLoopGenerator.kt index df7ecd44be7..36cf35bf794 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForInOptimizedIndicesLoopGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForInOptimizedIndicesLoopGenerator.kt @@ -28,21 +28,18 @@ abstract class ForInOptimizedIndicesLoopGenerator( codegen: ExpressionCodegen, forExpression: KtForExpression, loopRangeCall: ResolvedCall<*> -) : AbstractForInRangeLoopGenerator(codegen, forExpression) { +) : AbstractForInExclusiveRangeLoopGenerator(codegen, forExpression) { protected val receiverValue: ReceiverValue = loopRangeCall.extensionReceiver!! protected val expectedReceiverType: KotlinType = ExpressionCodegen.getExpectedReceiverType(loopRangeCall) - override fun storeRangeStartAndEnd() { - loopParameter().store(StackValue.constant(0, asmElementType), codegen.v) + override fun generateFrom(): StackValue = + StackValue.constant(0, asmElementType) - val receiver = codegen.generateReceiverValue(receiverValue, false) - val receiverType = codegen.asmType(expectedReceiverType) - receiver.put(receiverType, codegen.v) - getReceiverSizeAsInt() - codegen.v.iconst(1) - codegen.v.sub(Type.INT_TYPE) - StackValue.local(endVar, asmElementType).store(StackValue.onStack(Type.INT_TYPE), codegen.v) - } + override fun generateTo(): StackValue = + StackValue.operation(Type.INT_TYPE) { v -> + codegen.generateReceiverValue(receiverValue, false).put(codegen.asmType(expectedReceiverType), v) + getReceiverSizeAsInt() + } /** * `(receiver -> size:I)` diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCharSequenceIndices.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCharSequenceIndices.kt index 82f6bec9ab2..fd762ae38be 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCharSequenceIndices.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCharSequenceIndices.kt @@ -12,4 +12,8 @@ fun test(s: CharSequence): Int { // 0 getStart // 0 getEnd // 0 getFirst -// 0 getLast \ No newline at end of file +// 0 getLast + +// 0 IF_ICMPGT +// 0 IF_ICMPEQ +// 1 IF_ICMPGE \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionImplicitReceiverIndices.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionImplicitReceiverIndices.kt index b4cbb0ff79b..d0671f45be0 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionImplicitReceiverIndices.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionImplicitReceiverIndices.kt @@ -12,4 +12,8 @@ fun Collection.sumIndices(): Int { // 0 getStart // 0 getEnd // 0 getFirst -// 0 getLast \ No newline at end of file +// 0 getLast + +// 0 IF_ICMPGT +// 0 IF_ICMPEQ +// 1 IF_ICMPGE \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionIndices.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionIndices.kt index 6a38b6e317d..3bb9a771284 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionIndices.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInCollectionIndices.kt @@ -11,4 +11,8 @@ fun test() { // 0 getStart // 0 getEnd // 0 getFirst -// 0 getLast \ No newline at end of file +// 0 getLast + +// 0 IF_ICMPGT +// 0 IF_ICMPEQ +// 1 IF_ICMPGE \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInObjectArrayIndices.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInObjectArrayIndices.kt index 318b4e240cf..3295579fc25 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInObjectArrayIndices.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInObjectArrayIndices.kt @@ -11,4 +11,8 @@ fun test() { // 0 getStart // 0 getEnd // 0 getFirst -// 0 getLast \ No newline at end of file +// 0 getLast + +// 0 IF_ICMPGT +// 0 IF_ICMPEQ +// 1 IF_ICMPGE \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInPrimitiveArrayIndices.kt b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInPrimitiveArrayIndices.kt index f182bf69b18..351599cdee1 100644 --- a/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInPrimitiveArrayIndices.kt +++ b/compiler/testData/codegen/bytecodeText/forLoop/forInIndices/forInPrimitiveArrayIndices.kt @@ -11,4 +11,8 @@ fun test() { // 0 getStart // 0 getEnd // 0 getFirst -// 0 getLast \ No newline at end of file +// 0 getLast + +// 0 IF_ICMPGT +// 0 IF_ICMPEQ +// 1 IF_ICMPGE \ No newline at end of file