From 81cd33e2fa9b5930784d3aed920eea0e3038e7f7 Mon Sep 17 00:00:00 2001 From: Tom Paoletti Date: Thu, 21 Mar 2013 19:42:22 -0700 Subject: [PATCH] Performance optimization: empty() instead of size()>0 empty() is guaranteed to be constant complexity for both vectors and lists, while size() has linear complexity for lists. --- src/ATC/trafficcontrol.cxx | 78 ++++++++++++++--------------- src/ATC/trafficcontrol.hxx | 6 +-- src/Aircraft/replay.cxx | 18 +++---- src/Airports/apt_loader.cxx | 2 +- src/Autopilot/analogcomponent.hxx | 4 +- src/Input/FGKeyboardInput.cxx | 2 +- src/Instrumentation/HUD/HUD.cxx | 4 +- src/Instrumentation/HUD/HUD.hxx | 1 + src/Instrumentation/KLN89/kln89.cxx | 4 +- src/Instrumentation/dclgps.hxx | 2 +- src/Instrumentation/mk_viii.cxx | 2 +- src/Instrumentation/newnavradio.cxx | 2 +- src/Main/locale.cxx | 4 +- src/Main/logger.cxx | 4 +- src/Main/metar_main.cxx | 2 +- src/Main/options.cxx | 4 +- src/Main/positioninit.cxx | 2 +- src/Main/subsystemFactory.cxx | 2 +- src/Network/generic.cxx | 2 +- src/Sound/sample_queue.cxx | 4 +- src/Traffic/Schedule.cxx | 2 +- src/Viewer/fg_os_osgviewer.cxx | 2 +- 22 files changed, 77 insertions(+), 76 deletions(-) diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index 137c68aeb..65d60ae52 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -65,7 +65,7 @@ time_t ActiveRunway::requestTimeSlot(time_t eta) time_t newEta; time_t separation = 90; bool found = false; - if (estimatedArrivalTimes.size() == 0) { + if (estimatedArrivalTimes.empty()) { estimatedArrivalTimes.push_back(eta); return eta; } else { @@ -191,7 +191,7 @@ void FGTrafficRecord::setPositionAndIntentions(int pos, { currentPos = pos; - if (intentions.size()) { + if (! intentions.empty()) { intVecIterator i = intentions.begin(); if ((*i) != pos) { SG_LOG(SG_ATC, SG_ALERT, @@ -223,7 +223,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other) //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl; result = true; } - // else if (other.intentions.size()) + // else if (! other.intentions.empty()) // { // cerr << "Start check 2" << endl; // intVecIterator i = other.intentions.begin(); @@ -233,7 +233,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other) // cerr << "Check Position and intentions: current matches other.intentions" << endl; // result = true; // } - else if (intentions.size()) { + else if (! intentions.empty()) { //cerr << "Start check 3" << endl; intVecIterator i = intentions.begin(); //while (!((i == intentions.end()) || ((*i) == other.currentPos))) @@ -277,7 +277,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,... if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0) return currentTargetNode; - if (intentions.size()) { + if (! intentions.empty()) { for (i = intentions.begin(); i != intentions.end(); i++) { if ((*i) > 0) { if (currentTargetNode == @@ -288,7 +288,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, } } } - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (i = other.intentions.begin(); i != other.intentions.end(); i++) { if ((*i) > 0) { @@ -300,7 +300,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, } } } - if (intentions.size() && other.intentions.size()) { + if (! intentions.empty() && ! other.intentions.empty()) { for (i = intentions.begin(); i != intentions.end(); i++) { for (j = other.intentions.begin(); j != other.intentions.end(); j++) { @@ -332,7 +332,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net, net->findSegment(other.currentPos)->getEnd()->getIndex(); if ((node == othernode) && (node != -1)) return true; - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (intVecIterator i = other.intentions.begin(); i != other.intentions.end(); i++) { if (*i > 0) { @@ -344,7 +344,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net, } //if (other.currentPos > 0) // othernode = net->findSegment(other.currentPos)->getEnd()->getIndex(); - //if (intentions.size()) + //if (! intentions.empty()) // { // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++) // { @@ -388,7 +388,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net, } } } - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (intVecIterator j = other.intentions.begin(); j != other.intentions.end(); j++) { // cerr << "Current segment 1 " << (*i) << endl; @@ -820,7 +820,7 @@ void FGTowerController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -830,7 +830,7 @@ void FGTowerController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { FGTrafficRecord rec; rec.setId(id); @@ -843,7 +843,7 @@ void FGTowerController::announcePosition(int id, activeTraffic.push_back(rec); // Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway. ActiveRunwayVecIterator rwy = activeRunways.begin(); - if (activeRunways.size()) { + if (! activeRunways.empty()) { while (rwy != activeRunways.end()) { if (rwy->getRunwayName() == intendedRoute->getRunway()) { break; @@ -874,7 +874,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon // Search whether the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -884,7 +884,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon } } // // update position of the current aircraft - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { SG_LOG(SG_ATC, SG_ALERT, "AI error: updating aircraft without traffic record at " << SG_ORIGIN); } else { @@ -957,7 +957,7 @@ void FGTowerController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -968,7 +968,7 @@ void FGTowerController::signOff(int id) } // If this aircraft has left the runway, we can clear the departure record for this runway ActiveRunwayVecIterator rwy = activeRunways.begin(); - if (activeRunways.size()) { + if (! activeRunways.empty()) { //while ((rwy->getRunwayName() != i->getRunway()) && (rwy != activeRunways.end())) { while (rwy != activeRunways.end()) { if (rwy->getRunwayName() == i->getRunway()) { @@ -984,7 +984,7 @@ void FGTowerController::signOff(int id) "AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN); } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN); } else { @@ -1005,7 +1005,7 @@ bool FGTowerController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1014,7 +1014,7 @@ bool FGTowerController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1029,7 +1029,7 @@ FGATCInstruction FGTowerController::getInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1038,7 +1038,7 @@ FGATCInstruction FGTowerController::getInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1084,7 +1084,7 @@ void FGStartupController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1094,7 +1094,7 @@ void FGStartupController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { FGTrafficRecord rec; rec.setId(id); @@ -1124,7 +1124,7 @@ bool FGStartupController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1133,7 +1133,7 @@ bool FGStartupController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1148,7 +1148,7 @@ FGATCInstruction FGStartupController::getInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1157,7 +1157,7 @@ FGATCInstruction FGStartupController::getInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1171,7 +1171,7 @@ void FGStartupController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1180,7 +1180,7 @@ void FGStartupController::signOff(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN); } else { @@ -1230,7 +1230,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1542,7 +1542,7 @@ void FGApproachController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1552,7 +1552,7 @@ void FGApproachController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { FGTrafficRecord rec; rec.setId(id); @@ -1575,7 +1575,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1585,7 +1585,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double } } // // update position of the current aircraft - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: updating aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1624,7 +1624,7 @@ void FGApproachController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1633,7 +1633,7 @@ void FGApproachController::signOff(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN); } else { @@ -1653,7 +1653,7 @@ bool FGApproachController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1662,7 +1662,7 @@ bool FGApproachController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { diff --git a/src/ATC/trafficcontrol.hxx b/src/ATC/trafficcontrol.hxx index 1a137d4a5..bdedf0e1e 100644 --- a/src/ATC/trafficcontrol.hxx +++ b/src/ATC/trafficcontrol.hxx @@ -479,7 +479,7 @@ public: virtual std::string getName(); virtual void update(double dt); bool hasActiveTraffic() { - return activeTraffic.size() != 0; + return ! activeTraffic.empty(); }; TrafficVector &getActiveTraffic() { return activeTraffic; @@ -516,7 +516,7 @@ public: virtual void update(double dt); bool hasActiveTraffic() { - return activeTraffic.size() != 0; + return ! activeTraffic.empty(); }; TrafficVector &getActiveTraffic() { return activeTraffic; @@ -558,7 +558,7 @@ public: ActiveRunway* getRunway(const std::string& name); bool hasActiveTraffic() { - return activeTraffic.size() != 0; + return ! activeTraffic.empty(); }; TrafficVector &getActiveTraffic() { return activeTraffic; diff --git a/src/Aircraft/replay.cxx b/src/Aircraft/replay.cxx index f483f4f53..30e5bf675 100644 --- a/src/Aircraft/replay.cxx +++ b/src/Aircraft/replay.cxx @@ -572,7 +572,7 @@ FGReplay::record(double time) { FGReplayData* r = NULL; - if (recycler.size()) + if (! recycler.empty()) { r = recycler.front(); recycler.pop_front(); @@ -588,7 +588,7 @@ void FGReplay::interpolate( double time, const replay_list_type &list) { // sanity checking - if ( list.size() == 0 ) + if ( list.empty() ) { // handle empty list return; @@ -639,7 +639,7 @@ FGReplay::replay( double time ) { replayMessage(time); - if ( short_term.size() > 0 ) { + if ( ! short_term.empty() ) { t1 = short_term.back()->sim_time; t2 = short_term.front()->sim_time; if ( time > t1 ) { @@ -649,7 +649,7 @@ FGReplay::replay( double time ) { return true; } else if ( time <= t1 && time >= t2 ) { interpolate( time, short_term ); - } else if ( medium_term.size() > 0 ) { + } else if ( ! medium_term.empty() ) { t1 = short_term.front()->sim_time; t2 = medium_term.back()->sim_time; if ( time <= t1 && time >= t2 ) @@ -660,7 +660,7 @@ FGReplay::replay( double time ) { t2 = medium_term.front()->sim_time; if ( time <= t1 && time >= t2 ) { interpolate( time, medium_term ); - } else if ( long_term.size() > 0 ) { + } else if ( ! long_term.empty() ) { t1 = medium_term.front()->sim_time; t2 = long_term.back()->sim_time; if ( time <= t1 && time >= t2 ) @@ -704,13 +704,13 @@ FGReplay::replay(double time, FGReplayData* pCurrentFrame, FGReplayData* pOldFra double FGReplay::get_start_time() { - if ( long_term.size() > 0 ) + if ( ! long_term.empty() ) { return long_term.front()->sim_time; - } else if ( medium_term.size() > 0 ) + } else if ( ! medium_term.empty() ) { return medium_term.front()->sim_time; - } else if ( short_term.size() ) + } else if ( ! short_term.empty() ) { return short_term.front()->sim_time; } else @@ -722,7 +722,7 @@ FGReplay::get_start_time() double FGReplay::get_end_time() { - if ( short_term.size() ) + if ( ! short_term.empty() ) { return short_term.back()->sim_time; } else diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx index e41db5a59..5833c02c3 100644 --- a/src/Airports/apt_loader.cxx +++ b/src/Airports/apt_loader.cxx @@ -366,7 +366,7 @@ private: const string& rwy_no_1(token[8]); const string& rwy_no_2(token[17]); - if ( rwy_no_1.size() == 0 || rwy_no_2.size() == 0 ) + if ( rwy_no_1.empty() || rwy_no_2.empty() ) return; double displ_thresh1 = atof( token[11].c_str() ); diff --git a/src/Autopilot/analogcomponent.hxx b/src/Autopilot/analogcomponent.hxx index fc658befe..c111f0995 100644 --- a/src/Autopilot/analogcomponent.hxx +++ b/src/Autopilot/analogcomponent.hxx @@ -115,7 +115,7 @@ protected: * values of <min> and/or <max>. */ inline double get_output_value() const { - return _output_list.size() == 0 ? 0.0 : clamp(_output_list[0]->getDoubleValue()); + return _output_list.empty() ? 0.0 : clamp(_output_list[0]->getDoubleValue()); } simgear::PropertyList _output_list; @@ -140,7 +140,7 @@ public: inline void AnalogComponent::disabled( double dt ) { - if( _feedback_if_disabled && _output_list.size() > 0 ) { + if( _feedback_if_disabled && ! _output_list.empty() ) { InputValue * input; if( (input = _valueInput.get_active() ) != NULL ) input->set_value( _output_list[0]->getDoubleValue() ); diff --git a/src/Input/FGKeyboardInput.cxx b/src/Input/FGKeyboardInput.cxx index fbbadd249..4cc139996 100644 --- a/src/Input/FGKeyboardInput.cxx +++ b/src/Input/FGKeyboardInput.cxx @@ -169,7 +169,7 @@ const FGCommonInput::binding_list_t & FGKeyboardInput::_find_key_bindings (unsig FGButton &b = bindings[k]; // Try it straight, first. - if (b.bindings[modifiers].size() > 0) + if (! b.bindings[modifiers].empty()) return b.bindings[modifiers]; // Alt-Gr is CTRL+ALT diff --git a/src/Instrumentation/HUD/HUD.cxx b/src/Instrumentation/HUD/HUD.cxx index d0f257cc4..766b0fed1 100644 --- a/src/Instrumentation/HUD/HUD.cxx +++ b/src/Instrumentation/HUD/HUD.cxx @@ -185,7 +185,7 @@ void HUD::draw(osg::State&) if (!isVisible()) return; - if (!_items.size() && !_ladders.size()) + if (_items.empty() && _ladders.empty()) return; if (is3D()) { @@ -321,7 +321,7 @@ void HUD::common_draw() _text_list.draw(); _line_list.draw(); - if (_stipple_line_list.size()) { + if (! _stipple_line_list.empty()) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x00FF); _stipple_line_list.draw(); diff --git a/src/Instrumentation/HUD/HUD.hxx b/src/Instrumentation/HUD/HUD.hxx index 22d27d847..95066d2ed 100644 --- a/src/Instrumentation/HUD/HUD.hxx +++ b/src/Instrumentation/HUD/HUD.hxx @@ -61,6 +61,7 @@ public: void add(const LineSegment& seg) { _list.push_back(seg); } void erase() { _list.erase(_list.begin(), _list.end()); } inline unsigned int size() const { return _list.size(); } + inline bool empty() const { return _list.empty(); } void draw() { glBegin(GL_LINES); std::vector::const_iterator it, end = _list.end(); diff --git a/src/Instrumentation/KLN89/kln89.cxx b/src/Instrumentation/KLN89/kln89.cxx index a084fea50..858869fbd 100644 --- a/src/Instrumentation/KLN89/kln89.cxx +++ b/src/Instrumentation/KLN89/kln89.cxx @@ -587,7 +587,7 @@ void KLN89::DtoPressed() { } else { _dir_page->SetId(_activeWaypoint.id); } - } else if(_curPage == 6 && _activePage->GetSubPage() == 3 && fgGetBool("/instrumentation/kln89/scan-pull") && _activeFP->waypoints.size()) { + } else if(_curPage == 6 && _activePage->GetSubPage() == 3 && fgGetBool("/instrumentation/kln89/scan-pull") && ! _activeFP->waypoints.empty()) { // NAV 4 _dir_page->SetId(((KLN89NavPage*)_activePage)->GetNav4WpId()); } else if(_curPage == 7 && _activePage->GetSubPage() == 0 && _mode == KLN89_MODE_CRSR) { @@ -658,7 +658,7 @@ void KLN89::MsgPressed() { // TODO - handle persistent messages such as SUA alerting. // (The message annunciation flashes before first view, but afterwards remains continuously lit with the message available // until the potential conflict no longer pertains). - if(_dispMsg && _messageStack.size()) { + if(_dispMsg && ! _messageStack.empty()) { _messageStack.pop_front(); } _dispMsg = !_dispMsg; diff --git a/src/Instrumentation/dclgps.hxx b/src/Instrumentation/dclgps.hxx index 405c5a70b..a49fafda8 100644 --- a/src/Instrumentation/dclgps.hxx +++ b/src/Instrumentation/dclgps.hxx @@ -97,7 +97,7 @@ typedef gps_waypoint_map::const_iterator gps_waypoint_map_const_iterator; class GPSFlightPlan { public: std::vector waypoints; - inline bool IsEmpty() { return(waypoints.size() == 0); } + inline bool IsEmpty() { return waypoints.empty(); } }; // TODO - probably de-public the internals of the next 2 classes and add some methods! diff --git a/src/Instrumentation/mk_viii.cxx b/src/Instrumentation/mk_viii.cxx index c1da1dd7b..9f89dbbb8 100644 --- a/src/Instrumentation/mk_viii.cxx +++ b/src/Instrumentation/mk_viii.cxx @@ -977,7 +977,7 @@ MK_VIII::IOHandler::TerrainClearanceFilter::update (double agl) // calculate average double new_value = 0; - if (samples.size() > 0) + if (! samples.empty()) { // time consuming loop => queue limited to 75 samples // (= 15seconds * 5samples/second) diff --git a/src/Instrumentation/newnavradio.cxx b/src/Instrumentation/newnavradio.cxx index 7d4b60f29..41b606c15 100644 --- a/src/Instrumentation/newnavradio.cxx +++ b/src/Instrumentation/newnavradio.cxx @@ -904,7 +904,7 @@ NavRadioImpl::~NavRadioImpl() void NavRadioImpl::init() { - if( 0 < _components.size() ) + if( ! _components.empty() ) return; _components.push_back( new VOR(_rootNode) ); diff --git a/src/Main/locale.cxx b/src/Main/locale.cxx index cdf4f6912..1d30dfed0 100644 --- a/src/Main/locale.cxx +++ b/src/Main/locale.cxx @@ -313,14 +313,14 @@ FGLocale::getLocalizedStrings(const char* id, const char* resource) if (_currentLocale) { simgear::PropertyList s = getLocalizedStrings(_currentLocale, id, resource); - if (s.size()) + if (! s.empty()) return s; } if (_defaultLocale) { simgear::PropertyList s = getLocalizedStrings(_defaultLocale, id, resource); - if (s.size()) + if (! s.empty()) return s; } } diff --git a/src/Main/logger.cxx b/src/Main/logger.cxx index 31f0a59c7..0e8109e0d 100644 --- a/src/Main/logger.cxx +++ b/src/Main/logger.cxx @@ -50,13 +50,13 @@ FGLogger::init () Log &log = _logs[_logs.size()-1]; string filename = child->getStringValue("filename"); - if (filename.size() == 0) { + if (filename.empty()) { filename = "fg_log.csv"; child->setStringValue("filename", filename.c_str()); } string delimiter = child->getStringValue("delimiter"); - if (delimiter.size() == 0) { + if (delimiter.empty()) { delimiter = ","; child->setStringValue("delimiter", delimiter.c_str()); } diff --git a/src/Main/metar_main.cxx b/src/Main/metar_main.cxx index e63e6763f..9158dc89a 100644 --- a/src/Main/metar_main.cxx +++ b/src/Main/metar_main.cxx @@ -330,7 +330,7 @@ void printReport(SGMetar *m) surface.push_back(buf); } - if (surface.size()) { + if (! surface.empty()) { vector::iterator rwysurf = surface.begin(); for (i = 0; rwysurf != surface.end(); rwysurf++, i++) { if (i) diff --git a/src/Main/options.cxx b/src/Main/options.cxx index b85ef26b0..70a48decc 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1775,7 +1775,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) setupRoot(); // system.fgfsrc handling - if( hostname.size() > 0 ) { + if( ! hostname.empty() ) { config.set(globals->get_fg_root()); config.append( "system.fgfsrc" ); config.concat( "." ); @@ -2160,7 +2160,7 @@ void Options::showUsage() const vector desc; desc = option[k]->getChildren("description"); - if (desc.size() > 0) { + if (! desc.empty()) { for ( unsigned int l = 0; l < desc.size(); l++) { string t = desc[l]->getStringValue(); diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index d189b917b..816e99783 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -329,7 +329,7 @@ static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned: FGNavList::TypeFilter filter(type); const nav_list_type navlist = FGNavList::findByIdentAndFreq( id.c_str(), freq, &filter ); - if (navlist.size() == 0 ) { + if (navlist.empty()) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " << id << ":" << freq ); return false; diff --git a/src/Main/subsystemFactory.cxx b/src/Main/subsystemFactory.cxx index 3931a6c8e..0c92aed91 100644 --- a/src/Main/subsystemFactory.cxx +++ b/src/Main/subsystemFactory.cxx @@ -209,7 +209,7 @@ do_reinit (const SGPropertyNode * arg) bool result = true; vector subsystems = arg->getChildren("subsystem"); - if (subsystems.size() == 0) { + if (subsystems.empty()) { globals->get_subsystem_mgr()->reinit(); } else { for ( unsigned int i = 0; i < subsystems.size(); i++ ) { diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index f31484f16..9906701d7 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -567,7 +567,7 @@ FGGeneric::reinit() // bad configuration return; } - if (!binary_mode && (line_separator.size() == 0 || + if (!binary_mode && (line_separator.empty() || *line_separator.rbegin() != '\n')) { SG_LOG(SG_IO, SG_WARN, diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx index ab4c213b9..e3aaae9f9 100644 --- a/src/Sound/sample_queue.cxx +++ b/src/Sound/sample_queue.cxx @@ -50,7 +50,7 @@ FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) : FGSampleQueue::~FGSampleQueue () { - while ( _messages.size() > 0 ) { + while ( ! _messages.empty() ) { delete _messages.front(); _messages.pop(); } @@ -92,7 +92,7 @@ FGSampleQueue::update (double dt) if ( !now_playing ) { // message queue idle, add next sound if we have one - if ( _messages.size() > 0 ) { + if ( ! _messages.empty() ) { SGSampleGroup::add( _messages.front(), msgid ); _messages.pop(); play_once( msgid ); diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 4ad1ed778..9f7939450 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -545,7 +545,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti continue; } } - if (flights.size()) { + if (! flights.empty()) { time_t arrival = flights.back()->getArrivalTime(); int groundTime = groundTimeFromRadius(); if ((*i)->getDepartureTime() < (arrival+(groundTime))) diff --git a/src/Viewer/fg_os_osgviewer.cxx b/src/Viewer/fg_os_osgviewer.cxx index edd2e6ce2..ffe10c0e0 100644 --- a/src/Viewer/fg_os_osgviewer.cxx +++ b/src/Viewer/fg_os_osgviewer.cxx @@ -350,7 +350,7 @@ void fgOSFullScreen() std::vector windows; viewer->getWindows(windows); - if (windows.size() == 0) + if (windows.empty()) return; // Huh?!? /* Toggling window fullscreen is only supported for the main GUI window. -- 2.39.5