forked from qt-creator/qt-creator
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 <tim.jenssen@qt.io>
This commit is contained in:
@@ -341,6 +341,11 @@ QStringView FilePath::host() const
|
|||||||
return QStringView{m_data}.mid(m_pathLen + m_schemeLen, m_hostLen);
|
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
|
QString FilePath::path() const
|
||||||
{
|
{
|
||||||
if (m_data.startsWith("/./"))
|
if (m_data.startsWith("/./"))
|
||||||
@@ -869,7 +874,7 @@ 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();
|
||||||
}
|
}
|
||||||
@@ -881,7 +886,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())
|
||||||
@@ -930,7 +935,7 @@ bool FilePath::isChildOf(const FilePath &s) const
|
|||||||
/// \returns whether path() startsWith \a s
|
/// \returns whether path() startsWith \a s
|
||||||
bool FilePath::startsWith(const QString &s) const
|
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
|
bool FilePath::endsWith(const QString &s) const
|
||||||
{
|
{
|
||||||
return path().endsWith(s, caseSensitivity());
|
return pathView().endsWith(s, caseSensitivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public:
|
|||||||
|
|
||||||
QStringView scheme() const;
|
QStringView scheme() const;
|
||||||
QStringView host() const;
|
QStringView host() const;
|
||||||
|
QStringView pathView() const;
|
||||||
QString path() const;
|
QString path() const;
|
||||||
|
|
||||||
void setParts(const QStringView scheme, const QStringView host, const QStringView path);
|
void setParts(const QStringView scheme, const QStringView host, const QStringView path);
|
||||||
|
|||||||
Reference in New Issue
Block a user