From 44653cdf4cf9469003c1278691c8f449d06a5e06 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 7 Jul 2022 16:26:38 +0200 Subject: QFixed: stream-line relational operators - make them hidden friends - take lhs and rhs each by value - noexcept - remove useless mixed relational operators with int: Every fix op i is now compiled as fix op QFixed(i) with no loss in performance. Pick-to: 6.4 Change-Id: If4d0a43fd964547de59fed4ba2cdfea0cf176809 Reviewed-by: Lars Knoll --- src/gui/painting/qfixed_p.h | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src/gui/painting') diff --git a/src/gui/painting/qfixed_p.h b/src/gui/painting/qfixed_p.h index de52e2e815..f18c5d9813 100644 --- a/src/gui/painting/qfixed_p.h +++ b/src/gui/painting/qfixed_p.h @@ -58,12 +58,17 @@ public: inline QFixed &operator-=(const QFixed &other) { val -= other.val; return *this; } constexpr inline QFixed operator-() const { return fromFixed(-val); } - constexpr inline bool operator==(const QFixed &other) const { return val == other.val; } - constexpr inline bool operator!=(const QFixed &other) const { return val != other.val; } - constexpr inline bool operator<(const QFixed &other) const { return val < other.val; } - constexpr inline bool operator>(const QFixed &other) const { return val > other.val; } - constexpr inline bool operator<=(const QFixed &other) const { return val <= other.val; } - constexpr inline bool operator>=(const QFixed &other) const { return val >= other.val; } +#define REL_OP(op) \ + friend constexpr bool operator op(QFixed lhs, QFixed rhs) noexcept \ + { return lhs.val op rhs.val; } + REL_OP(==) + REL_OP(!=) + REL_OP(< ) + REL_OP(> ) + REL_OP(<=) + REL_OP(>=) +#undef REL_OP + constexpr inline bool operator!() const { return !val; } inline QFixed &operator/=(int x) { val /= x; return *this; } @@ -130,19 +135,6 @@ constexpr inline QFixed operator+(uint i, const QFixed &d) { return d+i; } constexpr inline QFixed operator-(uint i, const QFixed &d) { return -(d-i); } // constexpr inline QFixed operator*(qreal d, const QFixed &d2) { return d2*d; } -constexpr inline bool operator==(const QFixed &f, int i) { return f.value() == i * 64; } -constexpr inline bool operator==(int i, const QFixed &f) { return f.value() == i * 64; } -constexpr inline bool operator!=(const QFixed &f, int i) { return f.value() != i * 64; } -constexpr inline bool operator!=(int i, const QFixed &f) { return f.value() != i * 64; } -constexpr inline bool operator<=(const QFixed &f, int i) { return f.value() <= i * 64; } -constexpr inline bool operator<=(int i, const QFixed &f) { return i * 64 <= f.value(); } -constexpr inline bool operator>=(const QFixed &f, int i) { return f.value() >= i * 64; } -constexpr inline bool operator>=(int i, const QFixed &f) { return i * 64 >= f.value(); } -constexpr inline bool operator<(const QFixed &f, int i) { return f.value() < i * 64; } -constexpr inline bool operator<(int i, const QFixed &f) { return i * 64 < f.value(); } -constexpr inline bool operator>(const QFixed &f, int i) { return f.value() > i * 64; } -constexpr inline bool operator>(int i, const QFixed &f) { return i * 64 > f.value(); } - #ifndef QT_NO_DEBUG_STREAM inline QDebug &operator<<(QDebug &dbg, const QFixed &f) { return dbg << f.toReal(); } -- cgit v1.2.3