diff --git a/src/common/lru_cache.h b/src/common/lru_cache.h index 55c9639c7..03e263eef 100644 --- a/src/common/lru_cache.h +++ b/src/common/lru_cache.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #pragma once @@ -85,6 +85,25 @@ public: } } + template + std::size_t RemoveMatchingItems(const Pred& pred) + { + std::size_t removed_count = 0; + for (auto iter = m_items.begin(); iter != m_items.end();) + { + if (pred(iter->first)) + { + iter = m_items.erase(iter); + removed_count++; + } + else + { + ++iter; + } + } + return removed_count; + } + template bool Remove(const KeyT& key) { diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index c7d026da7..24c7c849c 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -413,9 +413,11 @@ GPUTexture* ImGuiFullscreen::GetCachedTextureAsync(std::string_view name) return tex_ptr->get(); } -bool ImGuiFullscreen::InvalidateCachedTexture(const std::string& path) +bool ImGuiFullscreen::InvalidateCachedTexture(std::string_view path) { - return s_state.texture_cache.Remove(path); + // need to do a partial match on this because SVG + return (s_state.texture_cache.RemoveMatchingItems([&path](const std::string& key) { return key.starts_with(path); }) > + 0); } void ImGuiFullscreen::UploadAsyncTextures() diff --git a/src/util/imgui_fullscreen.h b/src/util/imgui_fullscreen.h index 755001469..7303aef5e 100644 --- a/src/util/imgui_fullscreen.h +++ b/src/util/imgui_fullscreen.h @@ -141,7 +141,7 @@ std::shared_ptr LoadTexture(std::string_view path, u32 svg_width = 0 GPUTexture* GetCachedTexture(std::string_view name); GPUTexture* GetCachedTexture(std::string_view name, u32 svg_width, u32 svg_height); GPUTexture* GetCachedTextureAsync(std::string_view name); -bool InvalidateCachedTexture(const std::string& path); +bool InvalidateCachedTexture(std::string_view path); void UploadAsyncTextures(); void BeginLayout();