From 8a84d4812f3812f07b0fcfd5e2f2eb94261069c6 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 17 Sep 2023 20:15:47 +1000 Subject: [PATCH] LRUCache: Use heterogeneous container --- common/LRUCache.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/common/LRUCache.h b/common/LRUCache.h index f5bf26ee1a..c2d058440d 100644 --- a/common/LRUCache.h +++ b/common/LRUCache.h @@ -1,5 +1,5 @@ /* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2022 PCSX2 Dev Team + * Copyright (C) 2002-2023 PCSX2 Dev Team * * PCSX2 is free software: you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Found- @@ -14,6 +14,7 @@ */ #pragma once +#include "HeterogeneousContainers.h" #include #include @@ -28,7 +29,7 @@ class LRUCache CounterType last_access; }; - using MapType = std::map; + using MapType = std::conditional_t, StringMap, std::map>; public: LRUCache(std::size_t max_capacity = 16, bool manual_evict = false) @@ -50,7 +51,7 @@ public: Evict(m_items.size() - m_max_capacity); } - template + template V* Lookup(const KeyT& key) { auto iter = m_items.find(key); @@ -97,24 +98,21 @@ public: } } - template + template bool Remove(const KeyT& key) { auto iter = m_items.find(key); if (iter == m_items.end()) return false; - m_items.erase(iter); return true; } - void SetManualEvict(bool block) { m_manual_evict = block; if (!m_manual_evict) ManualEvict(); } - void ManualEvict() { // evict if we went over