From f9d79684516f4af05d5739b65c5d54473cf646c2 Mon Sep 17 00:00:00 2001 From: saker Date: Wed, 20 Nov 2024 21:28:23 -0500 Subject: [PATCH] Improve get function --- include/SampleCache.h | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/include/SampleCache.h b/include/SampleCache.h index 9777ff759c1..6e5ccc1ace2 100644 --- a/include/SampleCache.h +++ b/include/SampleCache.h @@ -98,23 +98,16 @@ class SampleCache static auto get(const T& entry, std::unordered_map, Hash>& map, Args... args) { const auto it = map.find(entry); + const auto item = it == map.end() ? nullptr : it->second.lock(); - if (it == map.end()) + if (!item) { const auto buffer = std::make_shared(std::forward(args)...); - map.insert(std::make_pair(entry, buffer)); + map.emplace(entry, buffer); return buffer; } - const auto entryLock = it->second.lock(); - if (!entryLock) - { - const auto buffer = std::make_shared(std::forward(args)...); - map[entry] = buffer; - return buffer; - } - - return entryLock; + return item; } inline static std::unordered_map, Hash> s_audioFileMap;