Utils: collect host root dir once

This improves the startup performance ~30% on certain machines

Change-Id: Ic7b74d42b0e13ec1dd695d4f322de021b996c051
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
David Schulz
2023-08-31 12:11:16 +02:00
parent 616a0c0f77
commit b418c81414
7 changed files with 25 additions and 11 deletions

View File

@@ -225,7 +225,7 @@ bool FilePath::isRootPath() const
return true; return true;
} }
return *this == FilePath::fromString(QDir::rootPath()); return *this == HostOsInfo::root();
} }
QString FilePath::encodedHost() const QString FilePath::encodedHost() const
@@ -986,7 +986,7 @@ const QString &FilePath::specialRootName()
const QString &FilePath::specialRootPath() 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; return rootPath;
} }
@@ -998,7 +998,7 @@ const QString &FilePath::specialDeviceRootName()
const QString &FilePath::specialDeviceRootPath() 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; return deviceRootPath;
} }

View File

@@ -1053,10 +1053,8 @@ FileSystemNode *FileSystemModelPrivate::node(const QString &path, bool fetch) co
elementPath = host; elementPath = host;
elementPath.append(separator); elementPath.append(separator);
} else { } else {
if (!pathElements.at(0).contains(QLatin1Char(':'))) { if (!pathElements.at(0).contains(QLatin1Char(':')))
QString rootPath = QDir(longPath).rootPath(); pathElements.prepend(HostOsInfo::root().path());
pathElements.prepend(rootPath);
}
if (pathElements.at(0).endsWith(QLatin1Char('/'))) if (pathElements.at(0).endsWith(QLatin1Char('/')))
pathElements[0].chop(1); pathElements[0].chop(1);
} }

View File

@@ -4,6 +4,7 @@
#pragma once #pragma once
#include "../filepath.h" #include "../filepath.h"
#include "../hostosinfo.h"
#include <QtCore/private/qabstractfileengine_p.h> #include <QtCore/private/qabstractfileengine_p.h>
@@ -97,7 +98,7 @@ private:
// We only need QDir::cleanPath here, as the path is always // We only need QDir::cleanPath here, as the path is always
// a fs engine path and will not contain scheme:// etc. // a fs engine path and will not contain scheme:// etc.
const QString p = QDir::cleanPath(path()); 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_status = State::IteratingRoot;
((*m_baseIterator).*get(QAFEITag()))(p); ((*m_baseIterator).*get(QAFEITag()))(p);

View File

@@ -71,7 +71,7 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
return new FSEngineImpl(removeDoubleSlash(fileName)); 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 new RootInjectFSEngine(fileName);
return nullptr; return nullptr;

View File

@@ -3,8 +3,11 @@
#include "hostosinfo.h" #include "hostosinfo.h"
#include "filepath.h"
#include "utilstr.h" #include "utilstr.h"
#include <QDir>
#if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB) #if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB)
#include <QOpenGLContext> #include <QOpenGLContext>
#endif #endif
@@ -21,7 +24,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
using namespace Utils; namespace Utils {
Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive; Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive;
bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false; bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false;
@@ -116,3 +119,11 @@ std::optional<quint64> HostOsInfo::totalMemoryInstalledInBytes()
#endif #endif
return {}; return {};
} }
const FilePath &HostOsInfo::root()
{
static const FilePath rootDir = FilePath::fromUserInput(QDir::rootPath());
return rootDir;
}
} // namespace Utils

View File

@@ -21,6 +21,8 @@ QT_END_NAMESPACE
namespace Utils { namespace Utils {
class FilePath;
class QTCREATOR_UTILS_EXPORT HostOsInfo class QTCREATOR_UTILS_EXPORT HostOsInfo
{ {
public: public:
@@ -86,6 +88,8 @@ public:
static std::optional<quint64> totalMemoryInstalledInBytes(); static std::optional<quint64> totalMemoryInstalledInBytes();
static const FilePath &root();
private: private:
static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity; static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity;
static bool m_useOverrideFileNameCaseSensitivity; static bool m_useOverrideFileNameCaseSensitivity;

View File

@@ -125,7 +125,7 @@ Environment DesktopDevice::systemEnvironment() const
FilePath DesktopDevice::rootPath() const FilePath DesktopDevice::rootPath() const
{ {
if (id() == DESKTOP_DEVICE_ID) if (id() == DESKTOP_DEVICE_ID)
return FilePath::fromParts({}, {}, QDir::rootPath()); return HostOsInfo::root();
return IDevice::rootPath(); return IDevice::rootPath();
} }