From 53526e4d4bee772e98ce48b83c37bcfd53cf7241 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 18 Nov 2022 10:20:18 +0100 Subject: [PATCH] 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: Tim Jenssen --- src/libs/utils/filepath.cpp | 13 +++++++++---- src/libs/utils/filepath.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 55d5ca89a07..4c90f0e6931 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 { if (m_data.startsWith("/./")) @@ -869,7 +874,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(); } @@ -881,7 +886,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()) @@ -930,7 +935,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()); } /*! @@ -939,7 +944,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 f7ba8631bcb..d0fb810e465 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);