mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Minor performance improvement of subdir check
* follow T689 * no need to always get and init simulator directory as it will not change
This commit is contained in:
committed by
Mat Sutcliffe
parent
3dde201df0
commit
58b7c875bc
@@ -527,12 +527,21 @@ namespace BlackMisc
|
||||
|
||||
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QString &dir2)
|
||||
{
|
||||
QDir d1(dir1);
|
||||
if (dir1.isEmpty() || dir2.isEmpty()) { return false; }
|
||||
const QDir d2(dir2);
|
||||
return CDirectoryUtils::isSubDirectoryOf(dir1, d2);
|
||||
}
|
||||
|
||||
bool CDirectoryUtils::isSubDirectoryOf(const QString &dir1, const QDir &dir2)
|
||||
{
|
||||
QDir d1(dir1);
|
||||
do
|
||||
{
|
||||
if (d1 == d2) { return true; }
|
||||
} while (d1.cdUp());
|
||||
if (d1 == dir2) { return true; }
|
||||
}
|
||||
while (d1.cdUp());
|
||||
|
||||
// not found
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,8 +185,13 @@ namespace BlackMisc
|
||||
static bool isSameExistingDirectory(const QString &dir1, const QString &dir2);
|
||||
|
||||
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
|
||||
//! \remark testing on real directory structure
|
||||
static bool isSubDirectoryOf(const QString &dir1, const QString &dir2);
|
||||
|
||||
//! Is dir1 a subdirectory (possibly nested) of dir2 or the same directory
|
||||
//! \remark testing on real directory structure
|
||||
static bool isSubDirectoryOf(const QString &dir1, const QDir &dir2);
|
||||
|
||||
//! Result of directory comparison
|
||||
struct DirComparison
|
||||
{
|
||||
|
||||
@@ -567,11 +567,16 @@ namespace BlackSimPlugin
|
||||
if (package.isEmpty()) { continue; }
|
||||
packages.insert(it, { package.append('/') });
|
||||
}
|
||||
|
||||
// comment KB 2019-06
|
||||
// a package is one xsb_aircraft.txt file BB has 9, X-CSL has 76
|
||||
// the reason for the append("/")/chop "/" is explained here: https://discordapp.com/channels/539048679160676382/539925070550794240/594891288751505418
|
||||
const QDir simDir = getSimulatorSettings().getSimulatorDirectoryOrDefault();
|
||||
for (auto &package : packages)
|
||||
{
|
||||
Q_ASSERT(package.s.endsWith('/'));
|
||||
package.s.chop(1);
|
||||
if (CDirectoryUtils::isSubDirectoryOf(package.s, getSimulatorSettings().getSimulatorDirectoryOrDefault()))
|
||||
if (CDirectoryUtils::isSubDirectoryOf(package.s, simDir))
|
||||
{
|
||||
m_trafficProxy->loadPlanesPackage(package.s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user