1
0
Fork 0

Don't allocate string temporaries for comparisons.

This commit is contained in:
Tim Moore 2009-11-08 21:53:02 +01:00 committed by Tim Moore
parent 9bc4c938d2
commit c4e62cc69f

View file

@ -42,6 +42,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <cstring>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -70,6 +71,7 @@
#include "TrafficMgr.hxx" #include "TrafficMgr.hxx"
using std::sort; using std::sort;
using std::strcmp;
/****************************************************************************** /******************************************************************************
* TrafficManager * TrafficManager
@ -376,62 +378,60 @@ void FGTrafficManager::startElement (const char * name, const XMLAttributes &at
void FGTrafficManager::endElement (const char * name) { void FGTrafficManager::endElement (const char * name) {
//cout << "End element " << name << endl; //cout << "End element " << name << endl;
string element(name); const string& value = elementValueStack.back();
string value = elementValueStack.back();
elementValueStack.pop_back();
if (element == string("model")) if (!strcmp(name, "model"))
mdl = value; mdl = value;
else if (element == string("livery")) else if (!strcmp(name, "livery"))
livery = value; livery = value;
else if (element == string("home-port")) else if (!strcmp(name, "home-port"))
homePort = value; homePort = value;
else if (element == string("registration")) else if (!strcmp(name, "registration"))
registration = value; registration = value;
else if (element == string("airline")) else if (!strcmp(name, "airline"))
airline = value; airline = value;
else if (element == string("actype")) else if (!strcmp(name, "actype"))
acType = value; acType = value;
else if (element == string("required-aircraft")) else if (!strcmp(name, "required-aircraft"))
requiredAircraft = value; requiredAircraft = value;
else if (element == string("flighttype")) else if (!strcmp(name, "flighttype"))
flighttype = value; flighttype = value;
else if (element == string("radius")) else if (!strcmp(name, "radius"))
radius = atoi(value.c_str()); radius = atoi(value.c_str());
else if (element == string("offset")) else if (!strcmp(name, "offset"))
offset = atoi(value.c_str()); offset = atoi(value.c_str());
else if (element == string("performance-class")) else if (!strcmp(name, "performance-class"))
m_class = value; m_class = value;
else if (element == string("heavy")) else if (!strcmp(name, "heavy"))
{ {
if(value == string("true")) if(value == string("true"))
heavy = true; heavy = true;
else else
heavy = false; heavy = false;
} }
else if (element == string("callsign")) else if (!strcmp(name, "callsign"))
callsign = value; callsign = value;
else if (element == string("fltrules")) else if (!strcmp(name, "fltrules"))
fltrules = value; fltrules = value;
else if (element == string("port")) else if (!strcmp(name, "port"))
port = value; port = value;
else if (element == string("time")) else if (!strcmp(name, "time"))
timeString = value; timeString = value;
else if (element == string("departure")) else if (!strcmp(name, "departure"))
{ {
departurePort = port; departurePort = port;
departureTime = timeString; departureTime = timeString;
} }
else if (element == string("cruise-alt")) else if (!strcmp(name, "cruise-alt"))
cruiseAlt = atoi(value.c_str()); cruiseAlt = atoi(value.c_str());
else if (element == string("arrival")) else if (!strcmp(name, "arrival"))
{ {
arrivalPort = port; arrivalPort = port;
arrivalTime = timeString; arrivalTime = timeString;
} }
else if (element == string("repeat")) else if (!strcmp(name, "repeat"))
repeat = value; repeat = value;
else if (element == string("flight")) else if (!strcmp(name, "flight"))
{ {
// We have loaded and parsed all the information belonging to this flight // We have loaded and parsed all the information belonging to this flight
// so we temporarily store it. // so we temporarily store it.
@ -477,7 +477,7 @@ void FGTrafficManager::endElement (const char * name) {
requiredAircraft)); requiredAircraft));
requiredAircraft = ""; requiredAircraft = "";
} }
else if (element == string("aircraft")) else if (!strcmp(name, "aircraft"))
{ {
int proportion = (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100); int proportion = (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
int randval = rand() & 100; int randval = rand() & 100;
@ -533,6 +533,7 @@ void FGTrafficManager::endElement (const char * name) {
<< score); << score);
score = 0; score = 0;
} }
elementValueStack.pop_back();
} }
void FGTrafficManager::data (const char * s, int len) { void FGTrafficManager::data (const char * s, int len) {