Skip to content

Commit b3f1894

Browse files
committed
use ConcurrentHashMap
1 parent e6d04c6 commit b3f1894

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ insert_final_newline=true
99
ij_kotlin_imports_layout=*
1010
disabled_rules=filename
1111
[*.xml]
12-
indent_size=4
12+
indent_size=4
13+
[*.gradle]
14+
indent_size=4

library/src/main/java/com/hoc081098/viewbindingdelegate/internal/cache.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ internal sealed interface MethodCache {
3535
}
3636

3737
private abstract class AbstractMethodCache : MethodCache {
38-
private val cache: MutableMap<Class<out ViewBinding>, Method> = ConcurrentHashMap()
38+
private val cache = ConcurrentHashMap<Class<out ViewBinding>, Method>()
3939

40-
override fun <T : ViewBinding> getOrPut(clazz: Class<T>) =
40+
override fun <T : ViewBinding> getOrPut(clazz: Class<T>): Method =
4141
measureNanoTime("[${this::class.java.simpleName}-getOrPut] class=$clazz") {
42-
cache[clazz]?.let { return@measureNanoTime it }
43-
44-
clazz.findMethod().also {
45-
// Cache update.
46-
cache[clazz] = it
47-
}
42+
cache.getOrPut(clazz) { clazz.findMethod() }
4843
}
4944

5045
abstract fun <T : ViewBinding> Class<T>.findMethod(): Method

0 commit comments

Comments
 (0)