Skip to content

Commit

Permalink
QModelIndex: do not use compareThreeWayMulti() and asTuple()
Browse files Browse the repository at this point in the history
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 ece36a7.

Found in 6.8 API review.

Pick-to: 6.8
Change-Id: I8be4e5f56c350039acde78c2e591e29773f3472c
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
isolovev committed Aug 15, 2024
1 parent 3b2d9d4 commit 564f2cb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/corelib/itemmodels/qabstractitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <QtCore/qobject.h>
#include <QtCore/qvariant.h>

#include <tuple>

QT_REQUIRE_CONFIG(itemmodel);

QT_BEGIN_NAMESPACE
Expand Down Expand Up @@ -145,11 +143,22 @@ class QModelIndex
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
Expand Down

0 comments on commit 564f2cb

Please sign in to comment.