From b3f18941bd4ab7c2b4866edbb9c7ab5851aa004b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petrus=20Nguy=E1=BB=85n=20Th=C3=A1i=20H=E1=BB=8Dc?= Date: Fri, 5 Aug 2022 19:22:43 +0700 Subject: [PATCH] use ConcurrentHashMap --- .editorconfig | 4 +++- .../hoc081098/viewbindingdelegate/internal/cache.kt | 11 +++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.editorconfig b/.editorconfig index f35f69b..f9db9c7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,4 +9,6 @@ insert_final_newline=true ij_kotlin_imports_layout=* disabled_rules=filename [*.xml] -indent_size=4 \ No newline at end of file +indent_size=4 +[*.gradle] +indent_size=4 diff --git a/library/src/main/java/com/hoc081098/viewbindingdelegate/internal/cache.kt b/library/src/main/java/com/hoc081098/viewbindingdelegate/internal/cache.kt index 6034410..41660a8 100644 --- a/library/src/main/java/com/hoc081098/viewbindingdelegate/internal/cache.kt +++ b/library/src/main/java/com/hoc081098/viewbindingdelegate/internal/cache.kt @@ -35,16 +35,11 @@ internal sealed interface MethodCache { } private abstract class AbstractMethodCache : MethodCache { - private val cache: MutableMap, Method> = ConcurrentHashMap() + private val cache = ConcurrentHashMap, Method>() - override fun getOrPut(clazz: Class) = + override fun getOrPut(clazz: Class): Method = measureNanoTime("[${this::class.java.simpleName}-getOrPut] class=$clazz") { - cache[clazz]?.let { return@measureNanoTime it } - - clazz.findMethod().also { - // Cache update. - cache[clazz] = it - } + cache.getOrPut(clazz) { clazz.findMethod() } } abstract fun Class.findMethod(): Method