Optimize vtable building [KT-40652]
This commit is contained in:
committed by
LepilkinaElena
parent
4f725387ff
commit
b57b81afa8
+22
-12
@@ -286,6 +286,7 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context, va
|
|||||||
|
|
||||||
val methods = irClass.sortedOverridableOrOverridingMethods
|
val methods = irClass.sortedOverridableOrOverridingMethods
|
||||||
val newVtableSlots = mutableListOf<OverriddenFunctionInfo>()
|
val newVtableSlots = mutableListOf<OverriddenFunctionInfo>()
|
||||||
|
val overridenVtableSlots = mutableMapOf<IrSimpleFunction, OverriddenFunctionInfo>()
|
||||||
|
|
||||||
DEBUG_OUTPUT(0) {
|
DEBUG_OUTPUT(0) {
|
||||||
println()
|
println()
|
||||||
@@ -300,19 +301,28 @@ internal class ClassLayoutBuilder(val irClass: IrClass, val context: Context, va
|
|||||||
println("BUILDING INHERITED vTable")
|
println("BUILDING INHERITED vTable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val superVtableMap = superVtableEntries.groupBy { it.function }
|
||||||
|
methods.forEach { overridingMethod ->
|
||||||
|
overridingMethod.allOverriddenFunctions.forEach {
|
||||||
|
val superMethods = superVtableMap[it]
|
||||||
|
if (superMethods?.isNotEmpty() == true) {
|
||||||
|
newVtableSlots.add(OverriddenFunctionInfo(overridingMethod, it))
|
||||||
|
superMethods.forEach { superMethod ->
|
||||||
|
overridenVtableSlots[superMethod.overriddenFunction] =
|
||||||
|
OverriddenFunctionInfo(overridingMethod, superMethod.overriddenFunction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
val inheritedVtableSlots = superVtableEntries.map { superMethod ->
|
val inheritedVtableSlots = superVtableEntries.map { superMethod ->
|
||||||
val overridingMethod = methods.singleOrNull { it.overrides(superMethod.function) }
|
overridenVtableSlots[superMethod.overriddenFunction]?.also {
|
||||||
if (overridingMethod == null) {
|
DEBUG_OUTPUT(0) {
|
||||||
|
println("Taking overridden ${superMethod.overriddenFunction.render()} -> ${it.function.render()}")
|
||||||
DEBUG_OUTPUT(0) { println("Taking super ${superMethod.overriddenFunction.render()} -> ${superMethod.function.render()}") }
|
}
|
||||||
|
} ?: superMethod.also {
|
||||||
superMethod
|
DEBUG_OUTPUT(0) {
|
||||||
} else {
|
println("Taking super ${superMethod.overriddenFunction.render()} -> ${superMethod.function.render()}")
|
||||||
newVtableSlots.add(OverriddenFunctionInfo(overridingMethod, superMethod.function))
|
}
|
||||||
|
|
||||||
DEBUG_OUTPUT(0) { println("Taking overridden ${superMethod.overriddenFunction.render()} -> ${overridingMethod.render()}") }
|
|
||||||
|
|
||||||
OverriddenFunctionInfo(overridingMethod, superMethod.overriddenFunction)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user