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:
Klaus Basan
2019-06-30 15:56:28 +02:00
committed by Mat Sutcliffe
parent 3dde201df0
commit 58b7c875bc
3 changed files with 23 additions and 4 deletions

View File

@@ -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;
}