From b418c81414b5d1d0d41c08793f15de56f5bbbb26 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 31 Aug 2023 12:11:16 +0200 Subject: [PATCH] Utils: collect host root dir once This improves the startup performance ~30% on certain machines Change-Id: Ic7b74d42b0e13ec1dd695d4f322de021b996c051 Reviewed-by: Marcus Tillmanns --- src/libs/utils/filepath.cpp | 6 +++--- src/libs/utils/filesystemmodel.cpp | 6 ++---- .../utils/fsengine/fileiteratordevicesappender.h | 3 ++- src/libs/utils/fsengine/fsenginehandler.cpp | 2 +- src/libs/utils/hostosinfo.cpp | 13 ++++++++++++- src/libs/utils/hostosinfo.h | 4 ++++ .../projectexplorer/devicesupport/desktopdevice.cpp | 2 +- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index abafc7748e8..4ab0f502f74 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -225,7 +225,7 @@ bool FilePath::isRootPath() const return true; } - return *this == FilePath::fromString(QDir::rootPath()); + return *this == HostOsInfo::root(); } QString FilePath::encodedHost() const @@ -986,7 +986,7 @@ const QString &FilePath::specialRootName() const QString &FilePath::specialRootPath() { - static const QString rootPath = QDir::rootPath() + u"__qtc_devices__"; + static const QString rootPath = HostOsInfo::root().path() + u"__qtc_devices__"; return rootPath; } @@ -998,7 +998,7 @@ const QString &FilePath::specialDeviceRootName() const QString &FilePath::specialDeviceRootPath() { - static const QString deviceRootPath = QDir::rootPath() + u"__qtc_devices__/device"; + static const QString deviceRootPath = HostOsInfo::root().path() + u"__qtc_devices__/device"; return deviceRootPath; } diff --git a/src/libs/utils/filesystemmodel.cpp b/src/libs/utils/filesystemmodel.cpp index a6bce17cabc..fb0441185d1 100644 --- a/src/libs/utils/filesystemmodel.cpp +++ b/src/libs/utils/filesystemmodel.cpp @@ -1053,10 +1053,8 @@ FileSystemNode *FileSystemModelPrivate::node(const QString &path, bool fetch) co elementPath = host; elementPath.append(separator); } else { - if (!pathElements.at(0).contains(QLatin1Char(':'))) { - QString rootPath = QDir(longPath).rootPath(); - pathElements.prepend(rootPath); - } + if (!pathElements.at(0).contains(QLatin1Char(':'))) + pathElements.prepend(HostOsInfo::root().path()); if (pathElements.at(0).endsWith(QLatin1Char('/'))) pathElements[0].chop(1); } diff --git a/src/libs/utils/fsengine/fileiteratordevicesappender.h b/src/libs/utils/fsengine/fileiteratordevicesappender.h index 9aec917d6b7..a28f1190806 100644 --- a/src/libs/utils/fsengine/fileiteratordevicesappender.h +++ b/src/libs/utils/fsengine/fileiteratordevicesappender.h @@ -4,6 +4,7 @@ #pragma once #include "../filepath.h" +#include "../hostosinfo.h" #include @@ -97,7 +98,7 @@ private: // We only need QDir::cleanPath here, as the path is always // a fs engine path and will not contain scheme:// etc. const QString p = QDir::cleanPath(path()); - if (p.compare(QDir::rootPath(), Qt::CaseInsensitive) == 0) + if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) m_status = State::IteratingRoot; ((*m_baseIterator).*get(QAFEITag()))(p); diff --git a/src/libs/utils/fsengine/fsenginehandler.cpp b/src/libs/utils/fsengine/fsenginehandler.cpp index e020eebddac..55174bc75cd 100644 --- a/src/libs/utils/fsengine/fsenginehandler.cpp +++ b/src/libs/utils/fsengine/fsenginehandler.cpp @@ -71,7 +71,7 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const return new FSEngineImpl(removeDoubleSlash(fileName)); } - if (fixedFileName.compare(QDir::rootPath(), Qt::CaseInsensitive) == 0) + if (fixedFileName.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) return new RootInjectFSEngine(fileName); return nullptr; diff --git a/src/libs/utils/hostosinfo.cpp b/src/libs/utils/hostosinfo.cpp index bf038ea82d2..d8361266f08 100644 --- a/src/libs/utils/hostosinfo.cpp +++ b/src/libs/utils/hostosinfo.cpp @@ -3,8 +3,11 @@ #include "hostosinfo.h" +#include "filepath.h" #include "utilstr.h" +#include + #if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB) #include #endif @@ -21,7 +24,7 @@ #include #endif -using namespace Utils; +namespace Utils { Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive; bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false; @@ -116,3 +119,11 @@ std::optional HostOsInfo::totalMemoryInstalledInBytes() #endif return {}; } + +const FilePath &HostOsInfo::root() +{ + static const FilePath rootDir = FilePath::fromUserInput(QDir::rootPath()); + return rootDir; +} + +} // namespace Utils diff --git a/src/libs/utils/hostosinfo.h b/src/libs/utils/hostosinfo.h index 090bf9e6d4a..44880f7885c 100644 --- a/src/libs/utils/hostosinfo.h +++ b/src/libs/utils/hostosinfo.h @@ -21,6 +21,8 @@ QT_END_NAMESPACE namespace Utils { +class FilePath; + class QTCREATOR_UTILS_EXPORT HostOsInfo { public: @@ -86,6 +88,8 @@ public: static std::optional totalMemoryInstalledInBytes(); + static const FilePath &root(); + private: static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity; static bool m_useOverrideFileNameCaseSensitivity; diff --git a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp index 9f6c2a408f3..a5cee8b3a6a 100644 --- a/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/desktopdevice.cpp @@ -125,7 +125,7 @@ Environment DesktopDevice::systemEnvironment() const FilePath DesktopDevice::rootPath() const { if (id() == DESKTOP_DEVICE_ID) - return FilePath::fromParts({}, {}, QDir::rootPath()); + return HostOsInfo::root(); return IDevice::rootPath(); }