From 97cd0c8dc3e4727753dd2ce552398197b2163acc Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Fri, 17 Feb 2023 23:20:17 +0900 Subject: [PATCH 1/3] Remove unused cache --- .../com/fasterxml/jackson/module/kotlin/ReflectionCache.kt | 5 ----- 1 file changed, 5 deletions(-) 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..b9c57752e 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt @@ -40,8 +40,6 @@ internal class ReflectionCache(reflectionCacheSize: Int) { 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 } @@ -89,7 +87,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 } } From b8153b6ff9c67b385cbbae66c4a63b715df902ff Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 18 Feb 2023 21:08:45 +0900 Subject: [PATCH 2/3] Remove class to KClass cache Because the conversion from Class to KClass is cached on the Kotlin side --- .../module/kotlin/KotlinNamesAnnotationIntrospector.kt | 2 +- .../com/fasterxml/jackson/module/kotlin/ReflectionCache.kt | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) 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 b9c57752e..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,16 +32,12 @@ 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) - 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 } From 57e80137cf16e9cf425c2340439fc3aa761c9326 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 19 Feb 2023 15:59:55 +0900 Subject: [PATCH 3/3] Update release notes wrt #628 --- release-notes/CREDITS-2.x | 1 + release-notes/VERSION-2.x | 1 + 2 files changed, 2 insertions(+) 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)