Jvm Ir. Optimization: avoid 'IrClass.functions' call if it not necessary

This commit is contained in:
Mikhael Bogdanov
2019-06-03 10:20:26 +02:00
parent 171e226d58
commit 30ab11575d
@@ -44,6 +44,7 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
} }
val methodStubsToGenerate = generateRelevantStubMethods(irClass) val methodStubsToGenerate = generateRelevantStubMethods(irClass)
if (methodStubsToGenerate.isEmpty()) return
// We don't need to generate stub for existing methods, but for FAKE_OVERRIDE methods with ABSTRACT modality, // We don't need to generate stub for existing methods, but for FAKE_OVERRIDE methods with ABSTRACT modality,
// it means an abstract function in superclass that is not implemented yet, // it means an abstract function in superclass that is not implemented yet,
@@ -140,11 +141,22 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
return mutableClass.typeParameters.map { it.symbol }.zip(readOnlyClassTypeArguments).toMap() return mutableClass.typeParameters.map { it.symbol }.zip(readOnlyClassTypeArguments).toMap()
} }
private data class StubsForCollectionClass( private inner class StubsForCollectionClass(
val readOnlyClass: IrClassSymbol, val readOnlyClass: IrClassSymbol,
val mutableClass: IrClassSymbol, val mutableClass: IrClassSymbol
val mutableOnlyMethods: Collection<IrSimpleFunction> ) {
) val mutableOnlyMethods: Collection<IrSimpleFunction> by lazy {
val readOnlyMethodSignatures = readOnlyClass.functions.map { it.owner.toSignature() }.toHashSet()
mutableClass.functions
.map { it.owner }
.filter { it.toSignature() !in readOnlyMethodSignatures }
.toHashSet()
}
operator fun component1() = readOnlyClass
operator fun component2() = mutableClass
operator fun component3() = mutableOnlyMethods
}
private val preComputedStubs: Collection<StubsForCollectionClass> by lazy { private val preComputedStubs: Collection<StubsForCollectionClass> by lazy {
with(context.ir.symbols) { with(context.ir.symbols) {
@@ -158,12 +170,7 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
iterator to mutableIterator, iterator to mutableIterator,
listIterator to mutableListIterator listIterator to mutableListIterator
).map { (readOnlyClass, mutableClass) -> ).map { (readOnlyClass, mutableClass) ->
val readOnlyMethodSignatures = readOnlyClass.functions.map { it.owner.toSignature() }.toHashSet() StubsForCollectionClass(readOnlyClass, mutableClass)
val mutableMethods = mutableClass.functions
.map { it.owner }
.filter { it.toSignature() !in readOnlyMethodSignatures }
.toHashSet()
StubsForCollectionClass(readOnlyClass, mutableClass, mutableMethods)
} }
} }
} }