From 6dba8851a547a34827e118a072551215e1a85729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 4 Aug 2024 14:03:54 +0200 Subject: [PATCH] Refactor `CRaceHelper::IsStart` function Avoid duplicate calculation by extraction result of `GetPureMapIndex` in variable. Rename variable `Indices` to `Index`. Include `vector` instead of `list`, as the former is used but the latter is not. --- src/game/client/race.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/game/client/race.cpp b/src/game/client/race.cpp index 1ab7a0f41..e9593226c 100644 --- a/src/game/client/race.cpp +++ b/src/game/client/race.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -78,18 +78,21 @@ bool CRaceHelper::IsStart(CGameClient *pClient, vec2 Prev, vec2 Pos) { std::vector vIndices = pCollision->GetMapIndices(Prev, Pos); if(!vIndices.empty()) - for(int &Indice : vIndices) + { + for(const int Index : vIndices) { - if(pCollision->GetTileIndex(Indice) == TILE_START) + if(pCollision->GetTileIndex(Index) == TILE_START) return true; - if(pCollision->GetFTileIndex(Indice) == TILE_START) + if(pCollision->GetFTileIndex(Index) == TILE_START) return true; } + } else { - if(pCollision->GetTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_START) + const int Index = pCollision->GetPureMapIndex(Pos); + if(pCollision->GetTileIndex(Index) == TILE_START) return true; - if(pCollision->GetFTileIndex(pCollision->GetPureMapIndex(Pos)) == TILE_START) + if(pCollision->GetFTileIndex(Index) == TILE_START) return true; } }