File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
library/src/main/java/com/hoc081098/viewbindingdelegate/internal Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 25
25
package com.hoc081098.viewbindingdelegate.internal
26
26
27
27
import androidx.annotation.AnyThread
28
- import androidx.collection.ArrayMap
29
28
import androidx.viewbinding.ViewBinding
30
29
import java.lang.reflect.Method
30
+ import java.util.concurrent.ConcurrentHashMap
31
31
32
32
@AnyThread
33
33
internal sealed interface MethodCache {
34
34
fun <T : ViewBinding > getOrPut (clazz : Class <T >): Method
35
35
}
36
36
37
37
private abstract class AbstractMethodCache : MethodCache {
38
- private val cache: MutableMap <Class <out ViewBinding >, Method > = ArrayMap ()
38
+ private val cache: MutableMap <Class <out ViewBinding >, Method > = ConcurrentHashMap ()
39
39
40
40
override fun <T : ViewBinding > getOrPut (clazz : Class <T >) =
41
41
measureNanoTime(" [${this ::class .java.simpleName} -getOrPut] class=$clazz " ) {
42
- synchronized(cache) {
43
- cache.getOrPut(clazz) { clazz.findMethod() }
42
+ cache[clazz]?.let { return @measureNanoTime it }
43
+
44
+ clazz.findMethod().also {
45
+ // Cache update.
46
+ cache[clazz] = it
44
47
}
45
48
}
46
49
You can’t perform that action at this time.
0 commit comments