only get cache by key when need

Signed-off-by: lixingchi1 <lixingchi1@huawei.com>
This commit is contained in:
lixingchi1 2024-08-08 15:39:39 +08:00
parent a93a1780d2
commit 75e3e26863

View File

@ -409,36 +409,57 @@ public:
void ProcessCachedIndex(std::unordered_map<std::string, LazyForEachCacheChild>& cache,
std::set<int32_t>& idleIndexes)
{
const auto& cacheKeys = GetCacheKeys(idleIndexes);
std::set<std::string> cacheKeys;
auto expiringIter = expiringItem_.begin();
while (expiringIter != expiringItem_.end()) {
const auto& key = expiringIter->first;
const auto& node = expiringIter->second;
auto iter = idleIndexes.find(node.first);
if (iter != idleIndexes.end() && node.second) {
ProcessOffscreenNode(node.second, false);
if (node.first == preBuildingIndex_) {
cache.try_emplace(key, node);
} else {
cache.try_emplace(key, std::move(node));
cachedItems_.try_emplace(node.first, LazyForEachChild(key, nullptr));
idleIndexes.erase(iter);
}
expiringIter++;
LoadCacheByIndex(cache, idleIndexes, node, key, iter, expiringIter);
} else {
NotifyDataDeleted(node.second, static_cast<size_t>(node.first), true);
ProcessOffscreenNode(node.second, true);
NotifyItemDeleted(RawPtr(node.second), key);
if (cacheKeys.find(key) != cacheKeys.end()) {
cache.try_emplace(key, node);
expiringIter++;
} else {
expiringIter = expiringItem_.erase(expiringIter);
}
LoadCacheByKey(cache, idleIndexes, node, key, cacheKeys, expiringIter);
}
}
}
void LoadCacheByIndex(std::unordered_map<std::string, LazyForEachCacheChild>& cache, std::set<int32_t>& idleIndexes,
const LazyForEachCacheChild& node, const std::string& key, const std::set<int32_t>::iterator& iter,
std::unordered_map<std::string, LazyForEachCacheChild>::iterator& expiringIter)
{
ProcessOffscreenNode(node.second, false);
if (node.first == preBuildingIndex_) {
cache.try_emplace(key, node);
} else {
cache.try_emplace(key, std::move(node));
cachedItems_.try_emplace(node.first, LazyForEachChild(key, nullptr));
idleIndexes.erase(iter);
}
expiringIter++;
}
void LoadCacheByKey(std::unordered_map<std::string, LazyForEachCacheChild>& cache, std::set<int32_t>& idleIndexes,
const LazyForEachCacheChild& node, const std::string& key, std::set<std::string>& cacheKeys,
std::unordered_map<std::string, LazyForEachCacheChild>::iterator& expiringIter)
{
NotifyDataDeleted(node.second, static_cast<size_t>(node.first), true);
ProcessOffscreenNode(node.second, true);
NotifyItemDeleted(RawPtr(node.second), key);
if (!idleIndexes.empty() && cacheKeys.empty()) {
cacheKeys = GetCacheKeys(idleIndexes);
}
if (cacheKeys.find(key) != cacheKeys.end()) {
cache.try_emplace(key, node);
expiringIter++;
} else {
expiringIter = expiringItem_.erase(expiringIter);
}
}
void ProcessOffscreenNode(RefPtr<UINode> uiNode, bool remove)
{
if (uiNode) {