IR: optimize transformation of declarations/statements lists in-place

Also, inherit IrDeclarationBase from IrElementBase to be able to use a
cast to IrElementBase, which is faster than a cast to IrElement or
IrDeclaration.
This commit is contained in:
Alexander Udalov
2020-08-03 21:38:28 +02:00
parent 4f0585950e
commit fb8e39a621
9 changed files with 29 additions and 18 deletions
@@ -386,7 +386,7 @@ private fun replaceCallToDefaultPrimary(context: JsIrBackendContext, constructor
val thisSymbol = (((constructor.body as IrBlockBody).statements
.find { it is IrVariable && it.origin === ES6_THIS_VARIABLE_ORIGIN }) as IrVariable?)?.symbol ?: return
(constructor.body as IrBlockBody).statements.transform {
(constructor.body as IrBlockBody).statements.transformInPlace {
if (it is IrDelegatingConstructorCall) {
val superCtor = it.symbol.owner
val initFunc = context.mapping.constructorToInitFunction[superCtor]!!
@@ -501,7 +501,7 @@ private class LowerCtorHelper(
origin = ES6_THIS_VARIABLE_ORIGIN
}
(constructor.body as IrBlockBody).statements.transform {
(constructor.body as IrBlockBody).statements.transformInPlace {
if (it === superCall) newThis
else it
}
@@ -561,7 +561,7 @@ private fun changeIrConstructorToIrFunction(context: JsIrBackendContext, contain
}, null)
}
container.parentAsClass.declarations.transform {
container.parentAsClass.declarations.transformInPlace {
if (it === container) newConstructor else it
}