diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt index 9afe8230cea..623ba944ec5 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/FunctionCaller.kt @@ -75,7 +75,7 @@ internal abstract class FunctionCaller( ) { override fun call(args: Array<*>): Any? { checkArguments(args) - return member.newInstance(*argsWithReceiver(boundReceiver, args)) + return member.newInstance(boundReceiver, *args) } } @@ -111,7 +111,7 @@ internal abstract class FunctionCaller( class InstanceMethod(method: ReflectMethod) : Method(method) { override fun call(args: Array<*>): Any? { checkArguments(args) - return callMethod(args[0], args.dropFirstArg()) + return callMethod(args[0], args.dropFirst()) } } @@ -119,7 +119,7 @@ internal abstract class FunctionCaller( override fun call(args: Array<*>): Any? { checkArguments(args) checkObjectInstance(args.firstOrNull()) - return callMethod(null, args.dropFirstArg()) + return callMethod(null, args.dropFirst()) } } @@ -128,7 +128,7 @@ internal abstract class FunctionCaller( ) { override fun call(args: Array<*>): Any? { checkArguments(args) - return callMethod(null, argsWithReceiver(boundReceiver, args)) + return callMethod(null, arrayOf(boundReceiver, *args)) } } @@ -280,19 +280,8 @@ internal abstract class FunctionCaller( } companion object { - // TODO lazily allocate array at bound callers? - fun argsWithReceiver(receiver: Any?, args: Array): Array = - arrayOfNulls(args.size + 1).apply { - this[0] = receiver - System.arraycopy(args, 0, this, 1, args.size) - } - @Suppress("UNCHECKED_CAST") inline fun Array.dropFirst(): Array = if (size <= 1) emptyArray() else copyOfRange(1, size) as Array - - @Suppress("UNCHECKED_CAST") - fun Array<*>.dropFirstArg(): Array = - (this as Array).dropFirst() } }