@@ -4,6 +4,7 @@ import com.mapk.fastkfunction.argumentbucket.ArgumentBucket
4
4
import com.mapk.fastkfunction.argumentbucket.BucketGenerator
5
5
import com.mapk.fastkfunction.spreadwrapper.ForConstructor
6
6
import com.mapk.fastkfunction.spreadwrapper.ForKFunction
7
+ import com.mapk.fastkfunction.spreadwrapper.ForMethod
7
8
import java.lang.reflect.Method
8
9
import java.lang.reflect.Modifier
9
10
import kotlin.reflect.KFunction
@@ -61,23 +62,24 @@ sealed class FastKFunction<T> {
61
62
62
63
internal class TopLevelFunction <T >(
63
64
private val function : KFunction <T >,
64
- private val method : Method ,
65
+ method : Method ,
65
66
override val valueParameters : List <KParameter >
66
67
) : FastKFunction<T>() {
68
+ private val spreadWrapper = ForMethod (method, null )
67
69
override val bucketGenerator = BucketGenerator (valueParameters, null )
68
70
69
71
@Suppress(" UNCHECKED_CAST" )
70
72
override fun callBy (bucket : ArgumentBucket ): T = if (bucket.isFullInitialized()) {
71
- method.invoke( null , * bucket.getValueArray()) as T
73
+ spreadWrapper.call( bucket.getValueArray()) as T
72
74
} else {
73
75
function.callBy(bucket)
74
76
}
75
77
76
78
@Suppress(" UNCHECKED_CAST" )
77
- override fun callByCollection (args : Collection <Any ?>): T = method.invoke( null , * args.toTypedArray()) as T
79
+ override fun callByCollection (args : Collection <Any ?>): T = spreadWrapper.call( args.toTypedArray()) as T
78
80
79
81
@Suppress(" UNCHECKED_CAST" )
80
- override fun call (vararg args : Any? ): T = method.invoke( null , * args) as T
82
+ override fun call (vararg args : Any? ): T = spreadWrapper.call( args) as T
81
83
}
82
84
83
85
internal class TopLevelExtensionFunction <T >(
@@ -104,23 +106,25 @@ sealed class FastKFunction<T> {
104
106
105
107
internal class InstanceFunction <T >(
106
108
private val function : KFunction <T >,
107
- private val method : Method ,
108
- private val instance : Any ,
109
+ method : Method ,
110
+ instance : Any ,
109
111
override val bucketGenerator : BucketGenerator ,
110
112
override val valueParameters : List <KParameter >
111
113
) : FastKFunction<T>() {
114
+ private val spreadWrapper = ForMethod (method, instance)
115
+
112
116
@Suppress(" UNCHECKED_CAST" )
113
117
override fun callBy (bucket : ArgumentBucket ): T = if (bucket.isFullInitialized()) {
114
- method.invoke(instance, * bucket.getValueArray()) as T
118
+ spreadWrapper.call( bucket.getValueArray()) as T
115
119
} else {
116
120
function.callBy(bucket)
117
121
}
118
122
119
123
@Suppress(" UNCHECKED_CAST" )
120
- override fun callByCollection (args : Collection <Any ?>): T = method.invoke(instance, * args.toTypedArray()) as T
124
+ override fun callByCollection (args : Collection <Any ?>): T = spreadWrapper.call( args.toTypedArray()) as T
121
125
122
126
@Suppress(" UNCHECKED_CAST" )
123
- override fun call (vararg args : Any? ): T = method.invoke(instance, * args) as T
127
+ override fun call (vararg args : Any? ): T = spreadWrapper.call( args) as T
124
128
}
125
129
126
130
companion object {
0 commit comments