JVM: Always invoke get()/charAt() in optimized for-loop over

CharSequence.withIndex(), even if element variable is unused in
destructuring declaration.

#KT-34779 Fixed
This commit is contained in:
Mark Punzalan
2019-11-05 23:42:29 -08:00
committed by Dmitry Petrov
parent 411dc5d60e
commit f444702cf3
16 changed files with 506 additions and 4 deletions
@@ -63,12 +63,14 @@ class CharSequenceWithIndexForLoopGenerator(
}
override fun assignLoopParametersNextValues() {
v.load(charSeqVar, charSeqType)
v.load(indexVar, Type.INT_TYPE)
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C")
if (elementLoopComponent != null) {
v.load(charSeqVar, charSeqType)
v.load(indexVar, Type.INT_TYPE)
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C")
StackValue.local(elementLoopComponent.parameterVar, elementLoopComponent.parameterType)
.store(StackValue.onStack(Type.CHAR_TYPE), v)
} else {
v.pop()
}
}