perf: rootCache
Some checks are pending
Build-Apk / build (push) Waiting to run

This commit is contained in:
lisonge 2024-10-18 21:40:50 +08:00
parent 5a2455a20e
commit 24c57a81f3

View File

@ -35,14 +35,17 @@ class A11yContext(
private var parentCache = LruCache<AccessibilityNodeInfo, AccessibilityNodeInfo>(MAX_CACHE_SIZE)
var rootCache: AccessibilityNodeInfo? = null
private fun clearNodeCache() {
private fun clearNodeCache(t: Long = System.currentTimeMillis()) {
if (META.debuggable) {
val sizeList = listOf(childCache.size(), parentCache.size(), indexCache.size())
if (sizeList.any { it > 0 }) {
Log.d("cache", "clear cache -> $sizeList")
}
}
lastClearTime = t
if (rootCache?.packageName != topActivityFlow.value.appId) {
rootCache = null
}
try {
childCache.evictAll()
parentCache.evictAll()
@ -61,14 +64,12 @@ class A11yContext(
private fun clearNodeCacheIfTimeout() {
if (appChangeTime != lastAppChangeTime) {
lastAppChangeTime = appChangeTime
lastClearTime = System.currentTimeMillis()
clearNodeCache()
return
}
val t = System.currentTimeMillis()
if (t - lastClearTime > 30_000L) {
lastClearTime = t
clearNodeCache()
clearNodeCache(t)
}
}
@ -83,7 +84,7 @@ class A11yContext(
if (interruptInnerKey == interruptKey) return
interruptInnerKey = interruptKey
val rule = currentRule ?: return
if (!activityRuleFlow.value.currentRules.contains(rule)) return
if (!activityRuleFlow.value.currentRules.any { it === rule }) return
if (rule.isPriority()) return
if (META.debuggable) {
Log.d("guardInterrupt", "中断 rule=${rule.statusText()}")