From 34eb507a9dad9f910993ce11357580c0e32f51cd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 9 Mar 2020 12:04:49 -0400 Subject: [PATCH] CFactoryMgr: std::move function instances in AddFactory() std::function is allowed to allocate on the heap, so this potentially prevents unnecessary allocations. We can also use insert_or_assign() to prevent unnecessary default initialization of std::function that immediately get overridden. --- Runtime/CFactoryMgr.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/CFactoryMgr.hpp b/Runtime/CFactoryMgr.hpp index 722f30634..db048d82e 100644 --- a/Runtime/CFactoryMgr.hpp +++ b/Runtime/CFactoryMgr.hpp @@ -21,8 +21,8 @@ public: bool CanMakeMemory(const urde::SObjectTag& tag) const; CFactoryFnReturn MakeObjectFromMemory(const SObjectTag& tag, std::unique_ptr&& buf, int size, bool compressed, const CVParamTransfer& paramXfer, CObjectReference* selfRef); - void AddFactory(FourCC key, FFactoryFunc func) { m_factories[key] = func; } - void AddFactory(FourCC key, FMemFactoryFunc func) { m_memFactories[key] = func; } + void AddFactory(FourCC key, FFactoryFunc func) { m_factories.insert_or_assign(key, std::move(func)); } + void AddFactory(FourCC key, FMemFactoryFunc func) { m_memFactories.insert_or_assign(key, std::move(func)); } enum class ETypeTable : u8 { CLSN,