QListViewItem: add constexpr

This class is just a record with a bit of functionality on it.
To prevent pessimizing it compared to a C struct with the same
contents, mark all operations constexpr and remove the point-
less copy ctor (the generated one is just fine).

Converge on passing QRect, QSize, QPoint by value. Was mixed
cref and value passing before.

Saves ~1KiB each in text and data size on an UBSan build,
somewhat less, of course, on a normal one.

Change-Id: Ibae16792d822ff183a0c542380501978f2108d93
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2016-07-23 22:25:26 +03:00
parent 2fd3d8ea9e
commit 0cdae477e3

View File

@ -69,28 +69,28 @@ class QListViewItem
friend class QListModeViewBase;
friend class QIconModeViewBase;
public:
inline QListViewItem()
Q_DECL_CONSTEXPR QListViewItem()
: x(-1), y(-1), w(0), h(0), indexHint(-1), visited(0xffff) {}
inline QListViewItem(QRect r, int i)
Q_DECL_CONSTEXPR QListViewItem(QRect r, int i)
: x(r.x()), y(r.y()), w(qMin(r.width(), SHRT_MAX)), h(qMin(r.height(), SHRT_MAX)),
indexHint(i), visited(0xffff) {}
inline bool operator==(const QListViewItem &other) const {
Q_DECL_CONSTEXPR bool operator==(const QListViewItem &other) const {
return (x == other.x && y == other.y && w == other.w && h == other.h &&
indexHint == other.indexHint); }
inline bool operator!=(const QListViewItem &other) const
Q_DECL_CONSTEXPR bool operator!=(const QListViewItem &other) const
{ return !(*this == other); }
inline bool isValid() const
Q_DECL_CONSTEXPR bool isValid() const
{ return rect().isValid() && (indexHint > -1); }
inline void invalidate()
Q_DECL_RELAXED_CONSTEXPR void invalidate()
{ x = -1; y = -1; w = 0; h = 0; }
inline void resize(const QSize &size)
Q_DECL_RELAXED_CONSTEXPR void resize(QSize size)
{ w = qMin(size.width(), SHRT_MAX); h = qMin(size.height(), SHRT_MAX); }
inline void move(const QPoint &position)
Q_DECL_RELAXED_CONSTEXPR void move(QPoint position)
{ x = position.x(); y = position.y(); }
inline int width() const { return w; }
inline int height() const { return h; }
Q_DECL_CONSTEXPR int width() const { return w; }
Q_DECL_CONSTEXPR int height() const { return h; }
private:
inline QRect rect() const
Q_DECL_CONSTEXPR QRect rect() const
{ return QRect(x, y, w, h); }
int x, y;
short w, h;