diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 4b09dc529..6e68d4c2e 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -22,6 +22,7 @@ Ilya Ryzhenkov (@orangy) WrongWrong (@k163377) * #627: Merge creator cache for Constructor and Method +* #628: Remove unnecessary cache # 2.14.0 diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 604d4de7c..8110a36db 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -23,6 +23,7 @@ Co-maintainers: #580: Lazy load UNIT_TYPE (contributed by Ilya R) #627: Merge creator cache for Constructor and Method +#628: Remove unnecessary cache 2.14.2 (28-Jan-2023) 2.14.1 (21-Nov-2022) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt index 0f2e82ee7..565487f69 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -63,7 +63,7 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c private fun hasCreatorAnnotation(member: AnnotatedConstructor): Boolean { // don't add a JsonCreator to any constructor if one is declared already - val kClass = cache.kotlinFromJava(member.declaringClass as Class) + val kClass = member.declaringClass.kotlin .apply { if (this in ignoredClassesForImplyingJsonCreator) return false } val kConstructor = cache.kotlinFromJava(member.annotated as Constructor) ?: return false diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt index 81400e869..97a925a5c 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt @@ -8,11 +8,9 @@ import com.fasterxml.jackson.databind.util.LRUMap import java.lang.reflect.Constructor import java.lang.reflect.Executable import java.lang.reflect.Method -import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.jvm.kotlinFunction - internal class ReflectionCache(reflectionCacheSize: Int) { sealed class BooleanTriState(val value: Boolean?) { class True : BooleanTriState(true) @@ -34,17 +32,11 @@ internal class ReflectionCache(reflectionCacheSize: Int) { } } - private val javaClassToKotlin = LRUMap, KClass>(reflectionCacheSize, reflectionCacheSize) private val javaConstructorToKotlin = LRUMap, KFunction>(reflectionCacheSize, reflectionCacheSize) private val javaMethodToKotlin = LRUMap>(reflectionCacheSize, reflectionCacheSize) private val javaExecutableToValueCreator = LRUMap>(reflectionCacheSize, reflectionCacheSize) private val javaConstructorIsCreatorAnnotated = LRUMap(reflectionCacheSize, reflectionCacheSize) private val javaMemberIsRequired = LRUMap(reflectionCacheSize, reflectionCacheSize) - private val kotlinGeneratedMethod = LRUMap(reflectionCacheSize, reflectionCacheSize) - - - fun kotlinFromJava(key: Class): KClass = javaClassToKotlin.get(key) - ?: key.kotlin.let { javaClassToKotlin.putIfAbsent(key, it) ?: it } fun kotlinFromJava(key: Constructor): KFunction? = javaConstructorToKotlin.get(key) ?: key.kotlinFunction?.let { javaConstructorToKotlin.putIfAbsent(key, it) ?: it } @@ -89,7 +81,4 @@ internal class ReflectionCache(reflectionCacheSize: Int) { fun javaMemberIsRequired(key: AnnotatedMember, calc: (AnnotatedMember) -> Boolean?): Boolean? = javaMemberIsRequired.get(key)?.value ?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, BooleanTriState.fromBoolean(it))?.value ?: it } - - fun isKotlinGeneratedMethod(key: AnnotatedMethod, calc: (AnnotatedMethod) -> Boolean): Boolean = kotlinGeneratedMethod.get(key) - ?: calc(key).let { kotlinGeneratedMethod.putIfAbsent(key, it) ?: it } }