From 1354de1780784b6921b61bc78ed239821a7076b1 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Mon, 28 Oct 2019 14:55:39 +0300 Subject: [PATCH] JVM_IR: stylistic, use transform instead of add/remove In InterfaceDeclarationLowering, functions are being replaced by redirections to default implementations. Use `transform`, as suggested by @pyos. --- .../jvm/lower/InterfaceDelegationLowering.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt index a78aba84e2b..f3b0b80e2e7 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt @@ -57,16 +57,11 @@ private class InterfaceDelegationLowering(val context: JvmBackendContext) : IrEl } private fun generateInterfaceMethods(irClass: IrClass) { - val toRemove = mutableListOf() - for (function in irClass.functions.toList()) { // Copy the list, because we are adding new declarations from the loop - function.getTargetForRedirection()?.let { implementation -> - toRemove.add(function) - - val delegation = generateDelegationToDefaultImpl(implementation, function) - irClass.declarations.add(delegation) - } + irClass.declarations.transform { declaration -> + (declaration as? IrSimpleFunction)?.getTargetForRedirection()?.let { implementation -> + generateDelegationToDefaultImpl(implementation, declaration) + } ?: declaration } - irClass.declarations.removeAll(toRemove) } private fun IrSimpleFunction.getTargetForRedirection(): IrSimpleFunction? {