From 0281029015b91826668b43a00126cd9b9fe9f4ab Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 15 Sep 2019 16:04:13 -0400 Subject: [PATCH] CEntityInfo: std::move vector in constructor Allows calling code to potentially avoid copies altogether by moving into the constructor. --- Runtime/CStateManager.cpp | 18 +++++++++--------- Runtime/World/CEntityInfo.hpp | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 9ef6b025c..7751c25a6 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -1292,21 +1292,21 @@ void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector std::pair CStateManager::LoadScriptObject(TAreaId aid, EScriptObjectType type, u32 length, CInputStream& in) { - TEditorId id = in.readUint32Big(); - u32 connCount = in.readUint32Big(); + const TEditorId id = in.readUint32Big(); + const u32 connCount = in.readUint32Big(); length -= 8; std::vector conns; conns.reserve(connCount); - for (int i = 0; i < connCount; ++i) { - EScriptObjectState state = EScriptObjectState(in.readUint32Big()); - EScriptObjectMessage msg = EScriptObjectMessage(in.readUint32Big()); - TEditorId target = in.readUint32Big(); + for (u32 i = 0; i < connCount; ++i) { + const auto state = EScriptObjectState(in.readUint32Big()); + const auto msg = EScriptObjectMessage(in.readUint32Big()); + const TEditorId target = in.readUint32Big(); length -= 12; conns.push_back(SConnection{state, msg, target}); } - u32 propCount = in.readUint32Big(); + const u32 propCount = in.readUint32Big(); length -= 4; - auto startPos = in.position(); + const auto startPos = in.position(); bool error = false; FScriptLoader loader = {}; @@ -1315,7 +1315,7 @@ std::pair CStateManager::LoadScriptObject(TAreaId aid, ESc CEntity* ent = nullptr; if (loader) { - CEntityInfo info(aid, conns, id); + const CEntityInfo info(aid, std::move(conns), id); ent = loader(*this, in, propCount, info); } else { error = true; diff --git a/Runtime/World/CEntityInfo.hpp b/Runtime/World/CEntityInfo.hpp index 51758e6fe..11916f8bf 100644 --- a/Runtime/World/CEntityInfo.hpp +++ b/Runtime/World/CEntityInfo.hpp @@ -18,8 +18,8 @@ class CEntityInfo { TEditorId x14_editorId; public: - CEntityInfo(TAreaId aid, const std::vector& conns, TEditorId eid = kInvalidEditorId) - : x0_areaId(aid), x4_conns(conns), x14_editorId(eid) {} + CEntityInfo(TAreaId aid, std::vector conns, TEditorId eid = kInvalidEditorId) + : x0_areaId(aid), x4_conns(std::move(conns)), x14_editorId(eid) {} TAreaId GetAreaId() const { return x0_areaId; } std::vector GetConnectionList() const { return x4_conns; } TEditorId GetEditorId() const { return x14_editorId; }