diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-07-07 16:26:38 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-08 22:14:52 +0200 |
commit | 44653cdf4cf9469003c1278691c8f449d06a5e06 (patch) | |
tree | 4ced1b518bf05faebeaa7dffa0a8bbc0010b55de /src/gui/painting | |
parent | 9b92f599406aaf218fd2be2f290dc4938049ade1 (diff) |
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 <lars.knoll@gmail.com>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qfixed_p.h | 30 |
1 files changed, 11 insertions, 19 deletions
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(); } |