JVM_IR: cache signatures in BridgeLowering

`mapAsmMethod` is somewhat slow, so this helps if there are a lot of
overrides of same methods and/or deep class hierarchies in a single file
(though it would probably help more if lowerings were not reconstructed
for every file).
This commit is contained in:
pyos
2020-02-27 11:29:12 +01:00
committed by Georgy Bronnikov
parent 97e320b57f
commit 456139fc5e
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.kotlin.utils.getOrPutNullable
import org.jetbrains.org.objectweb.asm.Type
@@ -480,8 +479,10 @@ private class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass,
private fun IrBuilderWithScope.irCastIfNeeded(expression: IrExpression, to: IrType): IrExpression =
if (expression.type == to || to.isAny() || to.isNullableAny()) expression else irImplicitCast(expression, to)
private val signatureCache = mutableMapOf<IrFunction, Method>()
private val IrFunction.jvmMethod: Method
get() = context.methodSignatureMapper.mapAsmMethod(this)
get() = signatureCache.getOrPut(this) { context.methodSignatureMapper.mapAsmMethod(this) }
}
private fun IrDeclaration.comesFromJava() = parentAsClass.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB