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>
This commit is contained in:
hjk
2022-11-18 10:20:18 +01:00
committed by Eike Ziller
parent ccd7365d7e
commit 3d492c47e7
2 changed files with 10 additions and 4 deletions

View File

@@ -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());
}
/*!