From 9df9a6303ff9fca353223a067dc689cd487f5b39 Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Wed, 8 Aug 2018 05:19:28 +0500 Subject: [PATCH] Fixed wrong range-based for usage We should use reference instead of a copy --- src/xrCore/LocatorAPI.cpp | 7 +++---- src/xrGame/GameObject.cpp | 2 +- src/xrGame/LevelGraphDebugRender.cpp | 2 +- src/xrGame/game_cl_deathmatch_buywnd.cpp | 2 +- src/xrGame/game_sv_capture_the_artefact.cpp | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/xrCore/LocatorAPI.cpp b/src/xrCore/LocatorAPI.cpp index d02f013efa6..8122916a860 100644 --- a/src/xrCore/LocatorAPI.cpp +++ b/src/xrCore/LocatorAPI.cpp @@ -135,7 +135,7 @@ XRCORE_API void _dump_open_files(int mode) { if (mode == 1) { - for (auto file : g_open_files) + for (const auto& file : g_open_files) { Log("----opened files"); if (file._reader != nullptr) @@ -145,9 +145,8 @@ XRCORE_API void _dump_open_files(int mode) else { Log("----un-used"); - for (auto itr : g_open_files) + for (const auto& file : g_open_files) { - auto file = itr; if (file._reader == nullptr) Msg("[%d] fname:%s", file._used, file._fn.c_str()); } @@ -894,7 +893,7 @@ void CLocatorAPI::_destroy() { CloseLog(); - for (auto it : m_files) + for (auto& it : m_files) { auto str = pstr(it.name); xr_free(str); diff --git a/src/xrGame/GameObject.cpp b/src/xrGame/GameObject.cpp index d5df16bcf84..b94c5abb8b8 100644 --- a/src/xrGame/GameObject.cpp +++ b/src/xrGame/GameObject.cpp @@ -1141,7 +1141,7 @@ void VisualCallback(IKinematics* tpKinematics) CGameObject* game_object = smart_cast(static_cast(tpKinematics->GetUpdateCallbackParam())); VERIFY(game_object); - for (auto cb : game_object->visual_callbacks()) + for (const auto& cb : game_object->visual_callbacks()) cb(tpKinematics); } diff --git a/src/xrGame/LevelGraphDebugRender.cpp b/src/xrGame/LevelGraphDebugRender.cpp index e3bf5a6c42c..7b49d5f6495 100644 --- a/src/xrGame/LevelGraphDebugRender.cpp +++ b/src/xrGame/LevelGraphDebugRender.cpp @@ -737,7 +737,7 @@ void LevelGraphDebugRender::DrawCovers() auto& nearest = coverPointCache; nearest.reserve(1000); ai().cover_manager().covers().nearest(Device.vCameraPosition, 5.0f, nearest); - for (auto coverPoint : nearest) + for (const auto& coverPoint : nearest) { // high cover Fvector pos = coverPoint->position(); diff --git a/src/xrGame/game_cl_deathmatch_buywnd.cpp b/src/xrGame/game_cl_deathmatch_buywnd.cpp index edf90689bb5..cbdb88db996 100644 --- a/src/xrGame/game_cl_deathmatch_buywnd.cpp +++ b/src/xrGame/game_cl_deathmatch_buywnd.cpp @@ -244,7 +244,7 @@ void game_cl_Deathmatch::SetBuyMenuItems(PRESET_ITEMS* pItems, BOOL OnlyPreset) pCurBuyMenu->ItemToRuck(pItem->object().cNameSect(), Addons); } }; - for (auto item : add_ammo) + for (const auto& item : add_ammo) AdditionalAmmoInserter(item); } else diff --git a/src/xrGame/game_sv_capture_the_artefact.cpp b/src/xrGame/game_sv_capture_the_artefact.cpp index ea64db89b86..3c0f4643bed 100644 --- a/src/xrGame/game_sv_capture_the_artefact.cpp +++ b/src/xrGame/game_sv_capture_the_artefact.cpp @@ -1959,9 +1959,9 @@ void game_sv_CaptureTheArtefact::OnDetachItem(CSE_ActorMP* actor, CSE_Abstract* if (EventPack.B.count > 2) u_EventSend(EventPack); - for (auto item : to_destroy) + for (const auto& item : to_destroy) DestroyGameItem(item); - for (auto item : to_reject) + for (const auto& item : to_reject) RejectGameItem(item); }; }