From 88c73d0ece38db4e3aa846cdc576aa75a908f399 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 27 May 2005 17:06:13 +0000 Subject: [PATCH] Don't try to open runway and parking files for every airport in the database. Works fine on Linux, but is a huge performance hit (1 minute) on cygwin. Keep a cache of actual directories and check that first. --- src/Airports/simple.cxx | 26 ++++++++++++++++++++++++-- src/Airports/simple.hxx | 5 ++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index 5ea71ac06..a516036c8 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -1149,6 +1149,26 @@ void FGAirport::chooseRunwayFallback(string *runway) * FGAirportList *****************************************************************************/ +// Populates a list of subdirectories of $FG_ROOT/Airports/AI so that +// the add() method doesn't have to try opening 2 XML files in each of +// thousands of non-existent directories. FIXME: should probably add +// code to free this list after parsing of apt.dat is finished; +// non-issue at the moment, however, as there are no AI subdirectories +// in the base package. +FGAirportList::FGAirportList() +{ + ulDir* d; + ulDirEnt* dent; + SGPath aid( globals->get_fg_root() ); + aid.append( "/Airports/AI" ); + if((d = ulOpenDir(aid.c_str())) == NULL) + return; + while((dent = ulReadDir(d)) != NULL) { + cerr << "Dent: " << dent->d_name; // DEBUG + ai_dirs.insert(dent->d_name); + } + ulCloseDir(d); +} // add an entry to the list void FGAirportList::add( const string id, const double longitude, @@ -1172,7 +1192,8 @@ void FGAirportList::add( const string id, const double longitude, rwyPrefPath.append( "/Airports/AI/" ); rwyPrefPath.append(id); rwyPrefPath.append("rwyuse.xml"); - if (parkpath.exists()) + if (ai_dirs.find(parkpath.str()) != ai_dirs.end() + && parkpath.exists()) { try { readXML(parkpath.str(),a); @@ -1181,7 +1202,8 @@ void FGAirportList::add( const string id, const double longitude, //cerr << "unable to read " << parkpath.str() << endl; } } - if (rwyPrefPath.exists()) + if (ai_dirs.find(rwyPrefPath.str()) != ai_dirs.end() + && rwyPrefPath.exists()) { try { readXML(rwyPrefPath.str(), rwyPrefs); diff --git a/src/Airports/simple.hxx b/src/Airports/simple.hxx index 40eed9758..9fe38fdbe 100644 --- a/src/Airports/simple.hxx +++ b/src/Airports/simple.hxx @@ -42,10 +42,12 @@ #include STL_STRING #include +#include #include SG_USING_STD(string); SG_USING_STD(map); +SG_USING_STD(set); SG_USING_STD(vector); typedef vector stringVec; @@ -306,11 +308,12 @@ private: airport_map airports_by_id; airport_list airports_array; + set < string > ai_dirs; public: // Constructor (new) - FGAirportList() {} + FGAirportList(); // Destructor ~FGAirportList();