Skip to content

Commit

Permalink
use ConcurrentHashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Aug 5, 2022
1 parent e6d04c6 commit b3f1894
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ insert_final_newline=true
ij_kotlin_imports_layout=*
disabled_rules=filename
[*.xml]
indent_size=4
indent_size=4
[*.gradle]
indent_size=4
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ internal sealed interface MethodCache {
}

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

override fun <T : ViewBinding> getOrPut(clazz: Class<T>) =
override fun <T : ViewBinding> getOrPut(clazz: Class<T>): 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 <T : ViewBinding> Class<T>.findMethod(): Method
Expand Down

0 comments on commit b3f1894

Please sign in to comment.