Skip to content

Commit

Permalink
FilePath: Fix pathView() and use at more places
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
e4z9 authored and hjk committed Nov 18, 2022
1 parent db76087 commit c84d122
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/libs/utils/filepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ QStringView FilePath::host() const

QStringView FilePath::pathView() const
{
return m_data.left(m_pathLen);
return QStringView(m_data).first(m_pathLen);
}

QString FilePath::path() const
Expand Down Expand Up @@ -869,9 +869,8 @@ QVariant FilePath::toVariant() const

bool FilePath::operator==(const FilePath &other) const
{
return QString::compare(path(), other.path(), caseSensitivity()) == 0
&& host() == other.host()
&& scheme() == other.scheme();
return pathView().compare(other.pathView(), caseSensitivity()) == 0 && host() == other.host()
&& scheme() == other.scheme();
}

bool FilePath::operator!=(const FilePath &other) const
Expand All @@ -881,7 +880,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())
Expand Down

0 comments on commit c84d122

Please sign in to comment.