diff --git a/src/App/Shared/ResourcePathRegistry.cpp b/src/App/Shared/ResourcePathRegistry.cpp index ecab5f5..1825f33 100644 --- a/src/App/Shared/ResourcePathRegistry.cpp +++ b/src/App/Shared/ResourcePathRegistry.cpp @@ -5,7 +5,7 @@ namespace { -constexpr auto SharedName = Red::CName("ResourcePathRegistryV2" BUILD_SUFFIX); +constexpr auto SharedName = Red::CName("ResourcePathRegistryV3" BUILD_SUFFIX); } App::ResourcePathRegistry::ResourcePathRegistry(const std::filesystem::path& aPreloadPath) @@ -16,11 +16,12 @@ App::ResourcePathRegistry::ResourcePathRegistry(const std::filesystem::path& aPr void App::ResourcePathRegistry::OnBootstrap() { - std::unique_lock lock(s_instance->m_mutex); + std::unique_lock lock(s_instance->m_lock); - if (!s_instance->m_hooked) + if (!s_instance->m_initialized) { - s_instance->m_hooked = true; + s_instance->m_initialized = true; + s_instance->m_map.reserve(400000); HookAfter(&OnCreatePath); } @@ -48,7 +49,8 @@ void App::ResourcePathRegistry::OnCreatePath(Red::ResourcePath* aPath, Red::Stri { if (aPathStr) { - std::scoped_lock _(s_instance->m_mutex); + std::scoped_lock _(s_instance->m_lock); + auto size = s_instance->m_map.size(); s_instance->m_map[*aPath] = {aPathStr->data, aPathStr->size}; } } @@ -58,7 +60,7 @@ std::string_view App::ResourcePathRegistry::ResolvePath(Red::ResourcePath aPath) if (!aPath) return {}; - std::shared_lock _(s_instance->m_mutex); + std::shared_lock _(s_instance->m_lock); const auto& it = s_instance->m_map.find(aPath); if (it == s_instance->m_map.end()) diff --git a/src/App/Shared/ResourcePathRegistry.hpp b/src/App/Shared/ResourcePathRegistry.hpp index db542a2..5919423 100644 --- a/src/App/Shared/ResourcePathRegistry.hpp +++ b/src/App/Shared/ResourcePathRegistry.hpp @@ -22,10 +22,10 @@ class ResourcePathRegistry protected: struct SharedInstance { - std::shared_mutex m_mutex; + Red::SharedSpinLock m_lock; Core::Map m_map; bool m_preloaded{false}; - bool m_hooked{false}; + bool m_initialized{false}; }; void OnBootstrap() override;