forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../filepath.h"
|
||||
#include "../hostosinfo.h"
|
||||
|
||||
#include <QtCore/private/qabstractfileengine_p.h>
|
||||
|
||||
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -3,8 +3,11 @@
|
||||
|
||||
#include "hostosinfo.h"
|
||||
|
||||
#include "filepath.h"
|
||||
#include "utilstr.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#if !defined(QT_NO_OPENGL) && defined(QT_GUI_LIB)
|
||||
#include <QOpenGLContext>
|
||||
#endif
|
||||
@@ -21,7 +24,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
using namespace Utils;
|
||||
namespace Utils {
|
||||
|
||||
Qt::CaseSensitivity HostOsInfo::m_overrideFileNameCaseSensitivity = Qt::CaseSensitive;
|
||||
bool HostOsInfo::m_useOverrideFileNameCaseSensitivity = false;
|
||||
@@ -116,3 +119,11 @@ std::optional<quint64> HostOsInfo::totalMemoryInstalledInBytes()
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
const FilePath &HostOsInfo::root()
|
||||
{
|
||||
static const FilePath rootDir = FilePath::fromUserInput(QDir::rootPath());
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -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<quint64> totalMemoryInstalledInBytes();
|
||||
|
||||
static const FilePath &root();
|
||||
|
||||
private:
|
||||
static Qt::CaseSensitivity m_overrideFileNameCaseSensitivity;
|
||||
static bool m_useOverrideFileNameCaseSensitivity;
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user