QModelIndex: do not use compareThreeWayMulti() and asTuple()
There are doubts that the implementation would result in a huge template bloat. Also, compareThreeWayMulti() seems to be inefficient, because it copies the tail over and over again. Rewrite the comparison helper functions to get rid of the compareThreeWayMulti() calls. This also allows us to drop the asTuple() method. Amends ece36a7394594ede3fba6744fb8f5b450a477652. Found in 6.8 API review. Change-Id: I8be4e5f56c350039acde78c2e591e29773f3472c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 564f2cbbddbca3f118198f0fb4ca0a97b95b8a59) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
aa9a991169
commit
a77987e600
@ -11,8 +11,6 @@
|
||||
#include <QtCore/qobject.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
#include <tuple>
|
||||
|
||||
QT_REQUIRE_CONFIG(itemmodel);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -145,11 +143,22 @@ public:
|
||||
constexpr inline bool isValid() const noexcept { return (r >= 0) && (c >= 0) && (m != nullptr); }
|
||||
|
||||
private:
|
||||
constexpr auto asTuple() const noexcept { return std::tie(r, c, i, m); }
|
||||
friend constexpr bool comparesEqual(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
|
||||
{ return lhs.asTuple() == rhs.asTuple(); }
|
||||
{
|
||||
return lhs.r == rhs.r && lhs.c == rhs.c && lhs.i == rhs.i && lhs.m == rhs.m;
|
||||
}
|
||||
friend constexpr Qt::strong_ordering compareThreeWay(const QModelIndex &lhs, const QModelIndex &rhs) noexcept
|
||||
{ return QtOrderingPrivate::compareThreeWayMulti(lhs.asTuple(), rhs.asTuple()); }
|
||||
{
|
||||
if (auto val = Qt::compareThreeWay(lhs.r, rhs.r); !is_eq(val))
|
||||
return val;
|
||||
if (auto val = Qt::compareThreeWay(lhs.c, rhs.c); !is_eq(val))
|
||||
return val;
|
||||
if (auto val = Qt::compareThreeWay(lhs.i, rhs.i); !is_eq(val))
|
||||
return val;
|
||||
if (auto val = Qt::compareThreeWay(lhs.m, rhs.m); !is_eq(val))
|
||||
return val;
|
||||
return Qt::strong_ordering::equivalent;
|
||||
}
|
||||
Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QModelIndex)
|
||||
private:
|
||||
inline QModelIndex(int arow, int acolumn, const void *ptr, const QAbstractItemModel *amodel) noexcept
|
||||
|
Loading…
x
Reference in New Issue
Block a user