forked from qt-creator/qt-creator
FilePath: Improve speed of ::relativePathFrom
Change-Id: Ie7aef2aeb01251edd6825fcd56a73ab65b57cbf5 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -19,9 +19,11 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QStringView>
|
#include <QStringView>
|
||||||
#include <QUrl>
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <QtConcurrent>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#ifdef QTCREATOR_PCH_H
|
#ifdef QTCREATOR_PCH_H
|
||||||
@@ -1497,21 +1499,28 @@ FilePath FilePath::relativePathFrom(const FilePath &anchor) const
|
|||||||
|
|
||||||
FilePath absPath;
|
FilePath absPath;
|
||||||
QString filename;
|
QString filename;
|
||||||
if (isFile()) {
|
|
||||||
|
const QList<FilePathInfo> infos
|
||||||
|
= QtConcurrent::blockingMapped(QList<FilePath>{*this, anchor}, [](const FilePath &path) {
|
||||||
|
return path.filePathInfo();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (infos.first().fileFlags.testFlag(FilePathInfo::FileFlag::FileType)) {
|
||||||
absPath = absolutePath();
|
absPath = absolutePath();
|
||||||
filename = fileName();
|
filename = fileName();
|
||||||
} else if (isDir()) {
|
} else if (infos.first().fileFlags.testFlag(FilePathInfo::FileFlag::DirectoryType)) {
|
||||||
absPath = absoluteFilePath();
|
absPath = absoluteFilePath();
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
FilePath absoluteAnchorPath;
|
FilePath absoluteAnchorPath;
|
||||||
if (anchor.isFile())
|
if (infos.last().fileFlags.testFlag(FilePathInfo::FileFlag::FileType))
|
||||||
absoluteAnchorPath = anchor.absolutePath();
|
absoluteAnchorPath = anchor.absolutePath();
|
||||||
else if (anchor.isDir())
|
else if (infos.last().fileFlags.testFlag(FilePathInfo::FileFlag::DirectoryType))
|
||||||
absoluteAnchorPath = anchor.absoluteFilePath();
|
absoluteAnchorPath = anchor.absoluteFilePath();
|
||||||
else
|
else
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
QString relativeFilePath = calcRelativePath(absPath.pathView(), absoluteAnchorPath.pathView());
|
QString relativeFilePath = calcRelativePath(absPath.pathView(), absoluteAnchorPath.pathView());
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
if (relativeFilePath == ".")
|
if (relativeFilePath == ".")
|
||||||
|
Reference in New Issue
Block a user