aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-18 10:20:18 +0100
committerEike Ziller <eike.ziller@qt.io>2022-11-24 10:10:21 +0000
commit3d492c47e76e67634a66ef90c1754e5e0f0d49f8 (patch)
treec0e0f7ace5e2e94844db4bc1559e5c70f641932b /src/libs
parentccd7365d7e8f300cc3a3d466b26a942fe6a06d4d (diff)
FilePath: Backport some pathView() changes
After the change to a single-string representation, the QString construction for path() is expensive for the comparison operators and simple convienience functions. Change-Id: I643c7115d3ad52f971d1692230b6eab82645b810 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/utils/filepath.cpp13
-rw-r--r--src/libs/utils/filepath.h1
2 files changed, 10 insertions, 4 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index fa969ee7a8..44aa572757 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -341,6 +341,11 @@ QStringView FilePath::host() const
return QStringView{m_data}.mid(m_pathLen + m_schemeLen, m_hostLen);
}
+QStringView FilePath::pathView() const
+{
+ return QStringView{m_data}.left(m_pathLen);
+}
+
QString FilePath::path() const
{
QTC_ASSERT(!m_data.startsWith(u"/./"), return m_data.mid(3, m_pathLen - 3));
@@ -871,7 +876,7 @@ QVariant FilePath::toVariant() const
bool FilePath::operator==(const FilePath &other) const
{
- return QString::compare(path(), other.path(), caseSensitivity()) == 0
+ return pathView().compare(other.pathView(), caseSensitivity()) == 0
&& host() == other.host()
&& scheme() == other.scheme();
}
@@ -883,7 +888,7 @@ bool FilePath::operator!=(const FilePath &other) const
bool FilePath::operator<(const FilePath &other) const
{
- const int cmp = QString::compare(path(), other.path(), caseSensitivity());
+ const int cmp = pathView().compare(other.pathView(), caseSensitivity());
if (cmp != 0)
return cmp < 0;
if (host() != other.host())
@@ -932,7 +937,7 @@ bool FilePath::isChildOf(const FilePath &s) const
/// \returns whether path() startsWith \a s
bool FilePath::startsWith(const QString &s) const
{
- return path().startsWith(s, caseSensitivity());
+ return pathView().startsWith(s, caseSensitivity());
}
/*!
@@ -941,7 +946,7 @@ bool FilePath::startsWith(const QString &s) const
*/
bool FilePath::endsWith(const QString &s) const
{
- return path().endsWith(s, caseSensitivity());
+ return pathView().endsWith(s, caseSensitivity());
}
/*!
diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h
index f7ba8631bc..d0fb810e46 100644
--- a/src/libs/utils/filepath.h
+++ b/src/libs/utils/filepath.h
@@ -74,6 +74,7 @@ public:
QStringView scheme() const;
QStringView host() const;
+ QStringView pathView() const;
QString path() const;
void setParts(const QStringView scheme, const QStringView host, const QStringView path);