Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 66d1ab8

Browse files
committed
呼び出し関連修正
1 parent 2779af0 commit 66d1ab8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/jmh/kotlin/com/mapk/fastkfunction/fastkfunction/CallObjectMethodBenchmark.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ open class CallObjectMethodBenchmark {
2323
.first { it.name == "companionObjectFun5" } as KFunction<Constructor5>
2424

2525
private val argumentMap: Map<KParameter, Any?> = functionByMethodReference.parameters.associateWith { it.index + 1 }
26+
private val argumentMapWithInstance: Map<KParameter, Any?> = functionByReflection.parameters.associateWith {
27+
if (it.kind == KParameter.Kind.INSTANCE) objectInstance else it.index + 1
28+
}
2629

2730
private val javaMethod: Method = functionByMethodReference.javaMethod!!
2831

@@ -50,10 +53,10 @@ open class CallObjectMethodBenchmark {
5053
fun functionByMethodReferenceCallBy(): Constructor5 = functionByMethodReference.callBy(argumentMap)
5154

5255
@Benchmark
53-
fun functionByReflectionCall(): Constructor5 = functionByReflection.call(1, 2, 3, 4, 5)
56+
fun functionByReflectionCall(): Constructor5 = functionByReflection.call(objectInstance, 1, 2, 3, 4, 5)
5457

5558
@Benchmark
56-
fun functionByReflectionCallBy(): Constructor5 = functionByReflection.callBy(argumentMap)
59+
fun functionByReflectionCallBy(): Constructor5 = functionByReflection.callBy(argumentMapWithInstance)
5760

5861
@Benchmark
5962
fun javaMethod(): Constructor5 = javaMethod.invoke(objectInstance, 1, 2, 3, 4, 5) as Constructor5

src/jmh/kotlin/com/mapk/fastkfunction/fastkfunction/CallTopLevelExtensionFunBenchmark.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ open class CallTopLevelExtensionFunBenchmark {
1818
private val functionFromClass: KFunction<Constructor5> = Constructor5::topLevelExtensionFun5
1919

2020
private val argumentMap: Map<KParameter, Any?> = functionByMethodReference.parameters.associateWith { it.index + 1 }
21+
private val argumentMapWithInstance: Map<KParameter, Any?> = functionFromClass.parameters.associateWith {
22+
if (it.kind == KParameter.Kind.EXTENSION_RECEIVER) receiverInstance else it.index + 1
23+
}
2124

2225
private val javaMethod: Method = functionByMethodReference.javaMethod!!
2326

@@ -43,10 +46,10 @@ open class CallTopLevelExtensionFunBenchmark {
4346
fun functionByMethodReferenceCallBy(): Constructor5 = functionByMethodReference.callBy(argumentMap)
4447

4548
@Benchmark
46-
fun functionFromClassCall(): Constructor5 = functionFromClass.call(1, 2, 3, 4, 5)
49+
fun functionFromClassCall(): Constructor5 = functionFromClass.call(receiverInstance, 1, 2, 3, 4, 5)
4750

4851
@Benchmark
49-
fun functionFromClassCallBy(): Constructor5 = functionFromClass.callBy(argumentMap)
52+
fun functionFromClassCallBy(): Constructor5 = functionFromClass.callBy(argumentMapWithInstance)
5053

5154
@Benchmark
5255
fun javaMethod(): Constructor5 = javaMethod.invoke(null, receiverInstance, 1, 2, 3, 4, 5) as Constructor5

src/jmh/kotlin/com/mapk/fastkfunction/singleargfastkfunction/CallTopLevelExtensionFunBenchmark.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ open class CallTopLevelExtensionFunBenchmark {
2020
private val functionFromClass: KFunction<Constructor1> = Constructor1::topLevelExtensionFun1
2121

2222
private val argumentMap: Map<KParameter, Any?> = mapOf(functionByMethodReference.parameters.single() to argument)
23+
private val argumentMapWithInstance: Map<KParameter, Any?> = functionFromClass.parameters.let {
24+
mapOf(
25+
it[0] to receiverInstance,
26+
it[1] to argument
27+
)
28+
}
2329

2430
private val javaMethod: Method = functionByMethodReference.javaMethod!!
2531

@@ -49,10 +55,10 @@ open class CallTopLevelExtensionFunBenchmark {
4955
fun functionByMethodReferenceCallBy(): Constructor1 = functionByMethodReference.callBy(argumentMap)
5056

5157
@Benchmark
52-
fun functionFromClassCall(): Constructor1 = functionFromClass.call(argument)
58+
fun functionFromClassCall(): Constructor1 = functionFromClass.call(receiverInstance, argument)
5359

5460
@Benchmark
55-
fun functionFromClassCallBy(): Constructor1 = functionFromClass.callBy(argumentMap)
61+
fun functionFromClassCallBy(): Constructor1 = functionFromClass.callBy(argumentMapWithInstance)
5662

5763
@Benchmark
5864
fun javaMethod(): Constructor1 = javaMethod.invoke(null, receiverInstance, argument) as Constructor1

0 commit comments

Comments
 (0)