perf: cache vid

This commit is contained in:
lisonge 2024-03-19 11:12:53 +08:00
parent 3a8fa8583d
commit 8169624e39

View File

@ -255,13 +255,29 @@ fun createCacheTransform(): CacheTransform {
} }
} }
} }
var vidCacheNode: AccessibilityNodeInfo? = null
var vidCacheValue: CharSequence? = null
val transform = Transform( val transform = Transform(
getAttr = { node, name -> getAttr = { node, name ->
if (name == "index") { when (name) {
node.getIndexX() "vid" -> {
if (node === vidCacheNode) {
vidCacheValue
} else { } else {
vidCacheNode = node
vidCacheValue = node.getVid()
vidCacheValue
}
}
"index" -> {
node.getIndexX()
}
else -> {
getAttr(node, name) getAttr(node, name)
} }
}
}, },
getName = { node -> node.className }, getName = { node -> node.className },
getChildren = getChildrenCache, getChildren = getChildrenCache,