yuzu-emu
/
yuzu
Archived
1
0
Fork 0

texture_cache: Use unordered_map::find instead of operator[] on hot code

This commit is contained in:
ReinUsesLisp 2020-05-27 17:59:04 -03:00
parent d2b2557542
commit b8b6f94ba9
1 changed files with 20 additions and 16 deletions

View File

@ -310,18 +310,20 @@ public:
dst_surface.first->MarkAsModified(true, Tick()); dst_surface.first->MarkAsModified(true, Tick());
} }
TSurface TryFindFramebufferSurface(VAddr addr) { TSurface TryFindFramebufferSurface(VAddr addr) const {
if (!addr) { if (!addr) {
return nullptr; return nullptr;
} }
const VAddr page = addr >> registry_page_bits; const VAddr page = addr >> registry_page_bits;
std::vector<TSurface>& list = registry[page]; const auto it = registry.find(page);
for (auto& surface : list) { if (it == registry.end()) {
if (surface->GetCpuAddr() == addr) { return nullptr;
return surface;
}
} }
return nullptr; const auto& list = it->second;
const auto found = std::find_if(list.begin(), list.end(), [addr](const auto& surface) {
return surface->GetCpuAddr() == addr;
});
return found != list.end() ? *found : nullptr;
} }
u64 Tick() { u64 Tick() {
@ -1130,18 +1132,20 @@ private:
return {}; return {};
} }
const VAddr cpu_addr_end = cpu_addr + size; const VAddr cpu_addr_end = cpu_addr + size;
VAddr start = cpu_addr >> registry_page_bits;
const VAddr end = (cpu_addr_end - 1) >> registry_page_bits; const VAddr end = (cpu_addr_end - 1) >> registry_page_bits;
VectorSurface surfaces; VectorSurface surfaces;
while (start <= end) { for (VAddr start = cpu_addr >> registry_page_bits; start <= end; ++start) {
std::vector<TSurface>& list = registry[start]; const auto it = registry.find(start);
for (auto& surface : list) { if (it == registry.end()) {
if (!surface->IsPicked() && surface->Overlaps(cpu_addr, cpu_addr_end)) { continue;
surface->MarkAsPicked(true); }
surfaces.push_back(surface); for (auto& surface : it->second) {
} if (surface->IsPicked() || !surface->Overlaps(cpu_addr, cpu_addr_end)) {
continue;
}
surface->MarkAsPicked(true);
surfaces.push_back(surface);
} }
start++;
} }
for (auto& surface : surfaces) { for (auto& surface : surfaces) {
surface->MarkAsPicked(false); surface->MarkAsPicked(false);