Enforce inlining for *Array constructors
This commit is contained in:
committed by
KonstantinAnisimov
parent
156a8d79c9
commit
666f052b10
+25
-1
@@ -56,7 +56,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
||||
|
||||
val irCall = super.visitCall(expression) as IrCall
|
||||
val functionDescriptor = irCall.descriptor as FunctionDescriptor
|
||||
if (!functionDescriptor.needsInlining) return irCall // This call does not need inlining.
|
||||
if (!needsInlining(functionDescriptor)) return irCall // This call does not need inlining.
|
||||
|
||||
val functionDeclaration = getFunctionDeclaration(irCall) // Get declaration of the function to be inlined.
|
||||
if (functionDeclaration == null) { // We failed to get the declaration.
|
||||
@@ -83,6 +83,28 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoidW
|
||||
return functionDeclaration as IrFunction?
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
// Enforce inlining of some constructors (ByteArray, IntArray, ...)
|
||||
|
||||
private fun needsInlining(functionDescriptor: FunctionDescriptor): Boolean {
|
||||
|
||||
val needsInlining = functionDescriptor.needsInlining
|
||||
val functionName = functionDescriptor.name.toString()
|
||||
if (functionName != "<init>") return needsInlining // This is not constructor.
|
||||
if (functionDescriptor.valueParameters.size != 2) return needsInlining // Constructor must have two parameters.
|
||||
|
||||
val returnType = functionDescriptor.returnType.toString()
|
||||
if (returnType == "DoubleArray") return true
|
||||
if (returnType == "FloatArray" ) return true
|
||||
if (returnType == "ByteArray" ) return true
|
||||
if (returnType == "ShortArray" ) return true
|
||||
if (returnType == "IntArray" ) return true
|
||||
if (returnType == "LongArray" ) return true
|
||||
if (returnType == "CharArray" ) return true
|
||||
|
||||
return needsInlining
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
override fun visitElement(element: IrElement) = element.accept(this, null)
|
||||
@@ -357,6 +379,8 @@ private class Inliner(val currentScope: ScopeWithIr, val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user