From d3279f1e0b2989a3ca9326d207b2b7432580b065 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 2 Apr 2024 15:51:53 +0200 Subject: [PATCH] FilePath: Improve speed of ::relativePathFrom Change-Id: Ie7aef2aeb01251edd6825fcd56a73ab65b57cbf5 Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 1b9b6e943c3..b62f222475c 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -19,9 +19,11 @@ #include #include #include -#include -#include #include +#include + +#include +#include #ifdef Q_OS_WIN #ifdef QTCREATOR_PCH_H @@ -1497,21 +1499,28 @@ FilePath FilePath::relativePathFrom(const FilePath &anchor) const FilePath absPath; QString filename; - if (isFile()) { + + const QList infos + = QtConcurrent::blockingMapped(QList{*this, anchor}, [](const FilePath &path) { + return path.filePathInfo(); + }); + + if (infos.first().fileFlags.testFlag(FilePathInfo::FileFlag::FileType)) { absPath = absolutePath(); filename = fileName(); - } else if (isDir()) { + } else if (infos.first().fileFlags.testFlag(FilePathInfo::FileFlag::DirectoryType)) { absPath = absoluteFilePath(); } else { return {}; } FilePath absoluteAnchorPath; - if (anchor.isFile()) + if (infos.last().fileFlags.testFlag(FilePathInfo::FileFlag::FileType)) absoluteAnchorPath = anchor.absolutePath(); - else if (anchor.isDir()) + else if (infos.last().fileFlags.testFlag(FilePathInfo::FileFlag::DirectoryType)) absoluteAnchorPath = anchor.absoluteFilePath(); else return {}; + QString relativeFilePath = calcRelativePath(absPath.pathView(), absoluteAnchorPath.pathView()); if (!filename.isEmpty()) { if (relativeFilePath == ".")