FilePath: Fix pathView() and use at more places

pathView was constructing a QStringView on a temporary, which silently
does weird stuff.

After the change to a single-string representation, the QString
construction for path() is expansive for the comparison operators.

Change-Id: I543c7115d3ad52f971d1692230b6eab82645b810
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2022-11-17 16:08:04 +01:00
committed by hjk
parent db76087213
commit c84d12227d

View File

@@ -342,7 +342,7 @@ QStringView FilePath::host() const
QStringView FilePath::pathView() const QStringView FilePath::pathView() const
{ {
return m_data.left(m_pathLen); return QStringView(m_data).first(m_pathLen);
} }
QString FilePath::path() const QString FilePath::path() const
@@ -869,9 +869,8 @@ QVariant FilePath::toVariant() const
bool FilePath::operator==(const FilePath &other) 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()
&& host() == other.host() && scheme() == other.scheme();
&& scheme() == other.scheme();
} }
bool FilePath::operator!=(const FilePath &other) const bool FilePath::operator!=(const FilePath &other) const
@@ -881,7 +880,7 @@ bool FilePath::operator!=(const FilePath &other) const
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) if (cmp != 0)
return cmp < 0; return cmp < 0;
if (host() != other.host()) if (host() != other.host())