aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-29 10:28:37 +0100
committerhjk <hjk@qt.io>2022-11-29 10:17:41 +0000
commit8249eabbadba2acdda5bebfd31f2be56a3c1928b (patch)
tree7759086be349a5c253beeed2e9a89a5daae1ccc8 /src/libs
parentf7d022009ba4ef00c93d6cb159edd4c058216e45 (diff)
Utils: FsEngine micro-optimizations
Mostly for shorter code, but also save a few cycles due to less string construction and run time dispatch. Also, make testFilePathFromToString() test two paths instead one path twice. Change-Id: I50a3145bca1a4b262a15e96173ea7ebd9cb678ad Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/utils/filepath.cpp39
-rw-r--r--src/libs/utils/filepath.h13
-rw-r--r--src/libs/utils/fsengine/fileiconprovider.cpp5
-rw-r--r--src/libs/utils/fsengine/fileiteratordevicesappender.h4
-rw-r--r--src/libs/utils/fsengine/fsenginehandler.cpp14
5 files changed, 33 insertions, 42 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index dcf1ff6d07..57cafaba17 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -200,8 +200,8 @@ QString FilePath::toString() const
return path();
if (isRelativePath())
- return scheme() + "://" + encodedHost() + "/./" + path();
- return scheme() + "://" + encodedHost() + path();
+ return scheme() + "://" + encodedHost() + "/./" + pathView();
+ return scheme() + "://" + encodedHost() + pathView();
}
QString FilePath::toFSPathString() const
@@ -210,8 +210,8 @@ QString FilePath::toFSPathString() const
return path();
if (isRelativePath())
- return specialPath(SpecialPathComponent::RootPath) + "/" + scheme() + "/" + encodedHost() + "/./" + path();
- return specialPath(SpecialPathComponent::RootPath) + "/" + scheme() + "/" + encodedHost() + path();
+ return specialRootPath() + '/' + scheme() + '/' + encodedHost() + "/./" + pathView();
+ return specialRootPath() + '/' + scheme() + '/' + encodedHost() + pathView();
}
QUrl FilePath::toUrl() const
@@ -710,25 +710,28 @@ FilePath FilePath::absoluteFilePath() const
return FilePath::currentWorkingPath().resolvePath(*this);
}
-QString FilePath::specialPath(SpecialPathComponent component)
+const QString &FilePath::specialRootName()
{
- switch (component) {
- case SpecialPathComponent::RootName:
- return QLatin1String("__qtc_devices__");
- case SpecialPathComponent::RootPath:
- return (QDir::rootPath() + "__qtc_devices__");
- case SpecialPathComponent::DeviceRootName:
- return QLatin1String("device");
- case SpecialPathComponent::DeviceRootPath:
- return QDir::rootPath() + "__qtc_devices__/device";
- }
+ static const QString rootName = "__qtc_devices__";
+ return rootName;
+}
+
+const QString &FilePath::specialRootPath()
+{
+ static const QString rootPath = QDir::rootPath() + u"__qtc_devices__";
+ return rootPath;
+}
- QTC_ASSERT(false, return {});
+const QString &FilePath::specialDeviceRootName()
+{
+ static const QString deviceRootName = "device";
+ return deviceRootName;
}
-FilePath FilePath::specialFilePath(SpecialPathComponent component)
+const QString &FilePath::specialDeviceRootPath()
{
- return FilePath::fromString(specialPath(component));
+ static const QString deviceRootPath = QDir::rootPath() + u"__qtc_devices__/device";
+ return deviceRootPath;
}
FilePath FilePath::normalizedPathName() const
diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h
index c91403b5f7..cf9cf2cf1b 100644
--- a/src/libs/utils/filepath.h
+++ b/src/libs/utils/filepath.h
@@ -223,15 +223,10 @@ public:
[[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info);
// Support for FSEngine. Do not use unless needed.
- enum class SpecialPathComponent {
- RootName,
- RootPath,
- DeviceRootName,
- DeviceRootPath,
- };
-
- [[nodiscard]] static QString specialPath(SpecialPathComponent component);
- [[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component);
+ [[nodiscard]] static const QString &specialRootName();
+ [[nodiscard]] static const QString &specialRootPath();
+ [[nodiscard]] static const QString &specialDeviceRootName();
+ [[nodiscard]] static const QString &specialDeviceRootPath();
[[nodiscard]] bool ensureReachable(const FilePath &other) const;
diff --git a/src/libs/utils/fsengine/fileiconprovider.cpp b/src/libs/utils/fsengine/fileiconprovider.cpp
index 12ca91e2a2..33762b0e36 100644
--- a/src/libs/utils/fsengine/fileiconprovider.cpp
+++ b/src/libs/utils/fsengine/fileiconprovider.cpp
@@ -174,8 +174,7 @@ QIcon FileIconProviderImplementation::icon(const QFileInfo &fi) const
return unknownFileIcon();
// Check if its one of the virtual devices directories
- if (filePath.path().startsWith(
- FilePath::specialPath(FilePath::SpecialPathComponent::RootPath))) {
+ if (filePath.path().startsWith(FilePath::specialRootPath())) {
// If the filepath does not need a device, it is a virtual device directory
if (!filePath.needsDevice())
return dirIcon();
@@ -221,7 +220,7 @@ QIcon FileIconProviderImplementation::icon(const FilePath &filePath) const
return unknownFileIcon();
// Check if its one of the virtual devices directories
- if (filePath.path().startsWith(FilePath::specialPath(FilePath::SpecialPathComponent::RootPath))) {
+ if (filePath.path().startsWith(FilePath::specialRootPath())) {
// If the filepath does not need a device, it is a virtual device directory
if (!filePath.needsDevice())
return dirIcon();
diff --git a/src/libs/utils/fsengine/fileiteratordevicesappender.h b/src/libs/utils/fsengine/fileiteratordevicesappender.h
index fbbd57ded8..b270bed150 100644
--- a/src/libs/utils/fsengine/fileiteratordevicesappender.h
+++ b/src/libs/utils/fsengine/fileiteratordevicesappender.h
@@ -74,7 +74,7 @@ public:
QString currentFileName() const override
{
if (m_status == State::Ended)
- return FilePath::specialPath(FilePath::SpecialPathComponent::RootPath);
+ return FilePath::specialRootPath();
setPath();
checkStatus();
@@ -83,7 +83,7 @@ public:
QFileInfo currentFileInfo() const override
{
if (m_status == State::Ended)
- return QFileInfo(FilePath::specialPath(FilePath::SpecialPathComponent::RootPath));
+ return QFileInfo(FilePath::specialRootPath());
setPath();
checkStatus();
return m_baseIterator->currentFileInfo();
diff --git a/src/libs/utils/fsengine/fsenginehandler.cpp b/src/libs/utils/fsengine/fsenginehandler.cpp
index 36cd0950ad..6bada88279 100644
--- a/src/libs/utils/fsengine/fsenginehandler.cpp
+++ b/src/libs/utils/fsengine/fsenginehandler.cpp
@@ -11,19 +11,15 @@
#include "../algorithm.h"
-namespace Utils {
-
-namespace Internal {
+namespace Utils::Internal {
QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
{
if (fileName.startsWith(':'))
return nullptr;
- static const QString rootPath =
- FilePath::specialPath(FilePath::SpecialPathComponent::RootPath);
- static const FilePath rootFilePath =
- FilePath::specialFilePath(FilePath::SpecialPathComponent::RootPath);
+ static const QString rootPath = FilePath::specialRootPath();
+ static const FilePath rootFilePath = FilePath::fromString(rootPath);
const QString fixedFileName = QDir::cleanPath(fileName);
@@ -60,6 +56,4 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
return nullptr;
}
-} // namespace Internal
-
-} // namespace Utils
+} // Utils::Internal