Skip to content

Commit

Permalink
Refine Kotlin inline class optimizations
Browse files Browse the repository at this point in the history
Closes gh-32334
  • Loading branch information
sdeleuze committed Mar 7, 2024
1 parent 5f601ce commit c1d4b61
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import kotlin.reflect.KClassifier;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
import kotlin.reflect.KType;
import kotlin.reflect.full.KCallables;
import kotlin.reflect.full.KClasses;
import kotlin.reflect.jvm.KCallablesJvm;
import kotlin.reflect.jvm.KTypesJvm;
import kotlin.reflect.jvm.ReflectJvmMapping;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.CoroutineStart;
Expand Down Expand Up @@ -117,19 +119,14 @@ public static Publisher<?> invokeSuspendingFunction(CoroutineContext context, Me
case VALUE, EXTENSION_RECEIVER -> {
Object arg = args[index];
if (!(parameter.isOptional() && arg == null)) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass) {
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
if (KotlinDetector.isInlineClass(javaClass)
&& !(parameter.getType().isMarkedNullable() && arg == null)) {
argMap.put(parameter, KClasses.getPrimaryConstructor(kClass).call(arg));
KType type = parameter.getType();
if (!(type.isMarkedNullable() && arg == null)) {
KClass<?> kClass = KTypesJvm.getJvmErasure(type);
if (KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
}
else {
argMap.put(parameter, arg);
}
}
else {
argMap.put(parameter, arg);
}
argMap.put(parameter, arg);
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import kotlin.reflect.KClass;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
import kotlin.reflect.KType;
import kotlin.reflect.full.KClasses;
import kotlin.reflect.jvm.KCallablesJvm;
import kotlin.reflect.jvm.KTypesJvm;
import kotlin.reflect.jvm.ReflectJvmMapping;

import org.springframework.context.MessageSource;
Expand Down Expand Up @@ -315,19 +317,14 @@ public static Object invokeFunction(Method method, Object target, Object[] args)
case VALUE, EXTENSION_RECEIVER -> {
Object arg = args[index];
if (!(parameter.isOptional() && arg == null)) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass) {
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
if (KotlinDetector.isInlineClass(javaClass)
&& !(parameter.getType().isMarkedNullable() && arg == null)) {
argMap.put(parameter, KClasses.getPrimaryConstructor(kClass).call(arg));
KType type = parameter.getType();
if (!(type.isMarkedNullable() && arg == null)) {
KClass<?> kClass = KTypesJvm.getJvmErasure(type);
if (KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
}
else {
argMap.put(parameter, arg);
}
}
else {
argMap.put(parameter, arg);
}
argMap.put(parameter, arg);
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import kotlin.reflect.KClass;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
import kotlin.reflect.KType;
import kotlin.reflect.full.KClasses;
import kotlin.reflect.jvm.KCallablesJvm;
import kotlin.reflect.jvm.KTypesJvm;
import kotlin.reflect.jvm.ReflectJvmMapping;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -326,19 +328,14 @@ public static Object invokeFunction(Method method, Object target, Object[] args,
case VALUE, EXTENSION_RECEIVER -> {
Object arg = args[index];
if (!(parameter.isOptional() && arg == null)) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass) {
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
if (KotlinDetector.isInlineClass(javaClass)
&& !(parameter.getType().isMarkedNullable() && arg == null)) {
argMap.put(parameter, KClasses.getPrimaryConstructor(kClass).call(arg));
KType type = parameter.getType();
if (!(type.isMarkedNullable() && arg == null)) {
KClass<?> kClass = KTypesJvm.getJvmErasure(type);
if (KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
arg = KClasses.getPrimaryConstructor(kClass).call(arg);
}
else {
argMap.put(parameter, arg);
}
}
else {
argMap.put(parameter, arg);
}
argMap.put(parameter, arg);
}
index++;
}
Expand Down

0 comments on commit c1d4b61

Please sign in to comment.