From f8d6d092fb93a9832c1e0aefd4f312551d619e09 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 30 Jan 2014 19:48:53 +0000 Subject: [PATCH] postpone variable definitions as long as possible (Effective C++ item 26) --- src/blackcore/context_network_atc.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/blackcore/context_network_atc.cpp b/src/blackcore/context_network_atc.cpp index 39a3f3dc4..914222940 100644 --- a/src/blackcore/context_network_atc.cpp +++ b/src/blackcore/context_network_atc.cpp @@ -105,15 +105,14 @@ namespace BlackCore CUserList CContextNetwork::getUsers() const { CUserList users; - CUser user; foreach(CAtcStation station, this->m_atcStationsOnline) { - user = station.getController(); + CUser user = station.getController(); users.push_back(user); } foreach(CAircraft aircraft, this->m_aircraftsInRange) { - user = aircraft.getPilot(); + CUser user = aircraft.getPilot(); users.push_back(user); } return users; @@ -127,17 +126,15 @@ namespace BlackCore CUserList users; if (callsigns.isEmpty()) return users; CCallsignList searchList(callsigns); - CUser user; - CCallsign callsign; // do aircrafts first, this will handle most callsigns foreach(CAircraft aircraft, this->m_aircraftsInRange) { if (searchList.isEmpty()) break; - callsign = aircraft.getCallsign(); + CCallsign callsign = aircraft.getCallsign(); if (searchList.contains(callsign)) { - user = aircraft.getPilot(); + CUser user = aircraft.getPilot(); users.push_back(user); searchList.remove(callsign); } @@ -146,10 +143,10 @@ namespace BlackCore foreach(CAtcStation station, this->m_atcStationsOnline) { if (searchList.isEmpty()) break; - callsign = station.getCallsign(); + CCallsign callsign = station.getCallsign(); if (searchList.contains(callsign)) { - user = station.getController(); + CUser user = station.getController(); users.push_back(user); searchList.remove(callsign); } @@ -158,7 +155,7 @@ namespace BlackCore // we might have unresolved callsigns foreach(CCallsign callsign, searchList) { - user = CUser(); + CUser user; user.setCallsign(callsign); users.push_back(user); }