Optimize Kotlin inline class checks
This commit fixes a performance regression caused by gh-31698, and more specifically by KClass#isValue invocations which are slow since they load the whole module to find the class to get the descriptor. After discussing with the Kotlin team, it has been decided that only checking for the presence of `@JvmInline` annotation is enough for Spring use case. As a consequence, this commit introduces a new KotlinDetector#isInlineClass method that performs such check, and BeanUtils, CoroutinesUtils and WebMVC/WebFlux InvocableHandlerMethod have been refined to leverage it. Closes gh-32334
This commit is contained in:
@@ -32,11 +32,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import kotlin.jvm.JvmClassMappingKt;
|
||||
import kotlin.jvm.JvmInline;
|
||||
import kotlin.reflect.KClass;
|
||||
import kotlin.reflect.KFunction;
|
||||
import kotlin.reflect.KParameter;
|
||||
import kotlin.reflect.full.KAnnotatedElements;
|
||||
import kotlin.reflect.full.KClasses;
|
||||
import kotlin.reflect.jvm.KCallablesJvm;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
@@ -874,8 +872,7 @@ public abstract class BeanUtils {
|
||||
if (primaryCtor == null) {
|
||||
return null;
|
||||
}
|
||||
if (kClass.isValue() && !KAnnotatedElements
|
||||
.findAnnotations(kClass, JvmClassMappingKt.getKotlinClass(JvmInline.class)).isEmpty()) {
|
||||
if (KotlinDetector.isInlineClass(clazz)) {
|
||||
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
|
||||
Assert.state(constructors.length == 1,
|
||||
"Kotlin value classes annotated with @JvmInline are expected to have a single JVM constructor");
|
||||
|
||||
Reference in New Issue
Block a user