Skip to content

Commit 13526be

Browse files
authored
Merge pull request #628 from k163377/remove-unnecessary-cache
Remove unnecessary cache
2 parents 234d824 + 57e8013 commit 13526be

File tree

4 files changed

+3
-12
lines changed

4 files changed

+3
-12
lines changed

release-notes/CREDITS-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Ilya Ryzhenkov (@orangy)
2222

2323
WrongWrong (@k163377)
2424
* #627: Merge creator cache for Constructor and Method
25+
* #628: Remove unnecessary cache
2526

2627
# 2.14.0
2728

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Co-maintainers:
2323
#580: Lazy load UNIT_TYPE
2424
(contributed by Ilya R)
2525
#627: Merge creator cache for Constructor and Method
26+
#628: Remove unnecessary cache
2627

2728
2.14.2 (28-Jan-2023)
2829
2.14.1 (21-Nov-2022)

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
6363
private fun hasCreatorAnnotation(member: AnnotatedConstructor): Boolean {
6464
// don't add a JsonCreator to any constructor if one is declared already
6565

66-
val kClass = cache.kotlinFromJava(member.declaringClass as Class<Any>)
66+
val kClass = member.declaringClass.kotlin
6767
.apply { if (this in ignoredClassesForImplyingJsonCreator) return false }
6868
val kConstructor = cache.kotlinFromJava(member.annotated as Constructor<Any>) ?: return false
6969

src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectionCache.kt

-11
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import com.fasterxml.jackson.databind.util.LRUMap
88
import java.lang.reflect.Constructor
99
import java.lang.reflect.Executable
1010
import java.lang.reflect.Method
11-
import kotlin.reflect.KClass
1211
import kotlin.reflect.KFunction
1312
import kotlin.reflect.jvm.kotlinFunction
1413

15-
1614
internal class ReflectionCache(reflectionCacheSize: Int) {
1715
sealed class BooleanTriState(val value: Boolean?) {
1816
class True : BooleanTriState(true)
@@ -34,17 +32,11 @@ internal class ReflectionCache(reflectionCacheSize: Int) {
3432
}
3533
}
3634

37-
private val javaClassToKotlin = LRUMap<Class<Any>, KClass<Any>>(reflectionCacheSize, reflectionCacheSize)
3835
private val javaConstructorToKotlin = LRUMap<Constructor<Any>, KFunction<Any>>(reflectionCacheSize, reflectionCacheSize)
3936
private val javaMethodToKotlin = LRUMap<Method, KFunction<*>>(reflectionCacheSize, reflectionCacheSize)
4037
private val javaExecutableToValueCreator = LRUMap<Executable, ValueCreator<*>>(reflectionCacheSize, reflectionCacheSize)
4138
private val javaConstructorIsCreatorAnnotated = LRUMap<AnnotatedConstructor, Boolean>(reflectionCacheSize, reflectionCacheSize)
4239
private val javaMemberIsRequired = LRUMap<AnnotatedMember, BooleanTriState?>(reflectionCacheSize, reflectionCacheSize)
43-
private val kotlinGeneratedMethod = LRUMap<AnnotatedMethod, Boolean>(reflectionCacheSize, reflectionCacheSize)
44-
45-
46-
fun kotlinFromJava(key: Class<Any>): KClass<Any> = javaClassToKotlin.get(key)
47-
?: key.kotlin.let { javaClassToKotlin.putIfAbsent(key, it) ?: it }
4840

4941
fun kotlinFromJava(key: Constructor<Any>): KFunction<Any>? = javaConstructorToKotlin.get(key)
5042
?: key.kotlinFunction?.let { javaConstructorToKotlin.putIfAbsent(key, it) ?: it }
@@ -89,7 +81,4 @@ internal class ReflectionCache(reflectionCacheSize: Int) {
8981

9082
fun javaMemberIsRequired(key: AnnotatedMember, calc: (AnnotatedMember) -> Boolean?): Boolean? = javaMemberIsRequired.get(key)?.value
9183
?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, BooleanTriState.fromBoolean(it))?.value ?: it }
92-
93-
fun isKotlinGeneratedMethod(key: AnnotatedMethod, calc: (AnnotatedMethod) -> Boolean): Boolean = kotlinGeneratedMethod.get(key)
94-
?: calc(key).let { kotlinGeneratedMethod.putIfAbsent(key, it) ?: it }
9584
}

0 commit comments

Comments
 (0)